#K93317. Road Network Optimization
Road Network Optimization
Road Network Optimization
In a city, the road network is represented as an undirected graph with (n) intersections and (m) roads connecting them. The city planners want to remove redundant roads while ensuring that the remaining roads in each connected region form a tree. This guarantees that there is exactly one unique shortest path between any two intersections in that region.
Mathematically, for each connected component containing (k) intersections, the maximum number of roads that can be kept is (k - 1). Therefore, if the graph has components with sizes (k_1, k_2, \dots, k_c), the overall maximum number of roads retained is (\sum_{i=1}^{c} (k_i - 1)).
Your task is to compute this maximum number given the list of roads.
inputFormat
The first line contains two integers (n) and (m), representing the number of intersections and the number of roads respectively. Then, there are (m) lines, each containing two integers (u) and (v) indicating that there is a road between intersections (u) and (v). Intersections are numbered from 1 to (n).
outputFormat
Output a single integer, the maximum number of roads that can be retained so that in each connected component the road network forms a tree (i.e. there exists a unique shortest path between any two intersections).## sample
6 7
1 2
1 3
3 4
3 5
4 5
4 6
5 6
5