CF387D.George and Interesting Graph

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

George loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria:

  • The graph doesn't contain any multiple arcs;
  • There is vertex vv (we'll call her the center), such that for any vertex of graph uu , the graph contains arcs (u,v)(u,v) and (v,u)(v,u) . Please note that the graph also contains loop (v,v)(v,v) .
  • The outdegree of all vertexes except for the center equals two and the indegree of all vertexes except for the center equals two. The outdegree of vertex uu is the number of arcs that go out of uu , the indegree of vertex uu is the number of arcs that go in uu . Please note that the graph can contain loops.

However, not everything's that simple. George got a directed graph of nn vertices and mm arcs as a present. The graph didn't have any multiple arcs. As George loves interesting graphs, he wants to slightly alter the presented graph and transform it into an interesting one. In one alteration he can either remove an arbitrary existing arc from the graph or add an arbitrary arc to the graph.

George wonders: what is the minimum number of changes that he needs to obtain an interesting graph from the graph he's got as a present? Help George and find the answer to the question.

输入格式

The first line contains two space-separated integers nn and mm ( 2<=n<=500,1<=m<=10002<=n<=500,1<=m<=1000 ) — the number of vertices and arcs in the presented graph.

Each of the next mm lines contains two space-separated integers ai,bia_{i},b_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ) — the descriptions of the graph's arcs. Pair (ai,bi)(a_{i},b_{i}) means that the graph contains an arc from vertex number aia_{i} to vertex number bib_{i} . It is guaranteed that the presented graph doesn't contain multiple arcs.

Assume that the grah vertices are numbered 1 through nn .

输出格式

Print a single integer — the answer to George's question.

输入输出样例

  • 输入#1

    3 7
    1 1
    2 2
    3 1
    1 3
    3 2
    2 3
    3 3
    

    输出#1

    0
    
  • 输入#2

    3 6
    1 1
    2 2
    3 1
    3 2
    2 3
    3 3
    

    输出#2

    1
    
  • 输入#3

    3 1
    2 2
    

    输出#3

    6
    

说明/提示

For more information about directed graphs, please visit: http://en.wikipedia.org/wiki/Directed_graph

In the first sample the graph already is interesting, its center is vertex 33 .

首页