Logo
(追記) (追記ここまで)

28330번 - Wooksin-ness of A Graph 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB54332554.348%

문제

At the headquarters of algospot.com, Toivoa “the chairman” has been pestering Astein “the slave” for a new graph problem for so long. So Astein came up with the following problem.

Wooksin-ness(욱신함) of an undirected graph $G(V, E)$ is defined as the minimum number of additional edges in order to have a cycle in the graph. Stated formally, you can write it as:

$\min |E' - E|$ $s.t.$ $E' ⊇ E$ and $G'(V, E')$ has at least one cycle

However, loops (edges that start and end at the same vertex) and multiple edges between a single pair of vertices are not allowed.

Write a program that calculates Wooksin-ness of given graph.

입력

The input consists of $T$ test cases. The number of test cases $T$ is given in the first line of the input.

The first line of each test case contains two integers $V$ and $E$ (1ドル ≤ V ≤ 100,ドル 0ドル ≤ E ≤ 1,000円$), where $V$ represents the number of vertices in the graph, and $E$ represents the number of edges. The vertices are numbered from 0ドル$ to $V - 1$. The following $E$ lines will each contain two integers, which are the number of two vertices connected by an edge.

There will be no loops in the input data. There will be at most one edge between a pair of vertices.

출력

Print exactly one line for each test case. The line should contain an integer indicating the minimum number of additional edges we need to add to the graph to get a cycle. If this is impossible, print -1 instead.

제한

예제 입력 1

2
3 2
0 1
2 0
3 3
0 1
1 2
2 0

예제 출력 1

1
0

힌트

출처

University > 전국 대학생 프로그래밍 대회 동아리 연합 > UCPC 2011 B번

  • 문제를 만든 사람: astein
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /