Submit | All submissions | Best solutions | Back to list |
EICONP4 - Convert Graph Into Tree |
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 ≤ 105), the number of edges m (1 ≤ m ≤ 2x105).
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 |
Output |
6 5 0 1 0 2 1 3 3 1 3 4 |
2 |
Added by: | Ha Minh Ngoc |
Date: | 2022-12-25 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |