#C627. Minimum Edge Removals for Tree Transformation
Minimum Edge Removals for Tree Transformation
Minimum Edge Removals for Tree Transformation
You are given an undirected graph with (n) vertices and (m) edges. Your task is to determine the minimum number of edges that must be removed so that the graph becomes a tree.
A tree is defined as a connected acyclic graph. In mathematical terms, a tree with (n) vertices always has exactly (n-1) edges, i.e. (E = n - 1). Removing unnecessary edges that form cycles will result in a tree structure.
inputFormat
The input is provided via standard input (stdin).
The first line contains two integers (n) and (m), representing the number of vertices and edges respectively. Each of the next (m) lines contains two space-separated integers (u) and (v), indicating an undirected edge between vertices (u) and (v).
outputFormat
Output a single integer via standard output (stdout) representing the minimum number of edges that need to be removed to transform the graph into a tree.
Recall that a tree is a connected acyclic graph and satisfies (E = n - 1), where (E) is the number of edges.## sample
7 7
1 2
2 3
3 4
4 5
5 6
6 1
3 7
1