#K33037. Minimum New Roads
Minimum New Roads
Minimum New Roads
You are given n cities (labeled from 1 to n) and m existing roads, where each road directly connects two different cities. Your task is to determine the minimum number of new roads that need to be constructed so that there is a direct road connecting every pair of distinct cities.
The total number of roads in a completely connected network (i.e. a complete graph) of n cities is given by the formula:
[ \frac{n(n-1)}{2} ]
If there are already m existing roads, then the answer is:
[ \frac{n(n-1)}{2} - m ]
Read the input from stdin
and output the answer to stdout
.
inputFormat
The first line contains two integers n and m, where n is the number of cities and m is the number of existing roads.
The next m lines each contain two integers u and v (1 ≤ u, v ≤ n, u ≠ v) indicating there is a road connecting city u and city v.
outputFormat
Output a single integer representing the minimum number of new roads that need to be constructed so that every pair of cities is directly connected.
## sample5 3
1 2
2 3
4 5
7