Problem C
Hoppers
You are part of an elite hacking group who has just invented a new type of malware, called the hoppers. Hoppers can operate in any high-security computer networks; however, they can only propagate themselves in a very limited way.
A computer network is a set of hosts
You are trying to infect all hosts in a particular high-security network by compromising a single host. Of course, a compromised host will be infected with a hopper. Though it may be an impossible mission, you realize that you can trick the administrator into installing new direct links between hosts by submitting IT requests.
Too many requests may arouse suspicion. Find the minimum number of IT requests you have to submit to ensure that there exists a single host such that if it is infected with a hopper, then it will propagate to the entire network.
Input
The first line contains two integers
Output
The output contains an integer in a line representing the minimum number of IT requests you must send.
Explanation
In the first example, there are
Sample Input 1 | Sample Output 1 |
---|---|
3 2 1 2 2 3 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
5 10 1 2 2 3 3 4 4 5 5 1 1 3 2 4 3 5 4 1 5 2 |
0 |
Sample Input 3 | Sample Output 3 |
---|---|
12 13 2 3 3 4 4 5 5 2 6 7 7 8 8 9 9 10 10 7 9 12 12 11 11 6 12 7 |
3 |