EICONP4 - Convert Graph Into Tree
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Given an undirected graph with ~n~ vertices and ~m~ edges. Vertices are numbered from ~0~ to ~n-1~. Write a program to calculate the minimum total number of edges should be removed and added to convert the given graph into a tree.
Input
- The first line contains the number of vertices ~n~ ~(1 ≤ n ≤ 10^5)~, the number of edges ~m~ ~(1 ≤ m ≤ 2 \times 10^5)~.
- Each of the next ~m~ lines contains ~2~ integers ~u, v~ representing an edge between ~u~ and ~v~ ~(0 ≤ u,v ≤ n)~.
Output
- Print out the total number of removed and added edges.
Sample Input
6 5
0 1
0 2
1 3
3 1
3 4
Samle Output
2
Bình luận