#ablc. [abl_c]Connect Cities
[abl_c]Connect Cities
Problem Statement
There are cities numbered through , and bidirectional roads numbered through . Road connects City and City .
Snuke can perform the following operation zero or more times:
- Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities.
After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).
What is the minimum number of roads he must build to achieve the goal?
Constraints
- No two roads connect the same pair of cities.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 1
1 2
Sample Output 1
1
Initially, there are three cities, and there is a road between City and City .
Snuke can achieve the goal by building one new road, for example, between City and City . After that,
- We can travel between and directly.
- We can travel between and directly.
- We can travel between and by following both roads ( - - ).