There is a magical castle in Northland. In this castle there are n rooms and each room contains saviour spirit which need to be freed to fight evil and save Northland. Once the spirit is freed it leads to destruction of the room, additionally there is a path where you and your friends are standing which is connected to each of rooms. The castle is so magical because if it connects room1 to room2 means, you can only go from room1 to room2 and not vice versa. The mystery doesn't end here, starting from a room say room(u) it is impossible to reach back to room(u) following any paths. Now you need to free all the saviours to save Northland and sacrifice yourself and friends for it. So determine the minimum of your friends who should accompany you for this holy task.
Imput Format:
First line consist two integer n, m. n is number of rooms and m is no of connections between rooms. Next m lines have two space seperated integers say u and v which denotes a way to go from room(u) to room(v). All u,v pairs are distinct where, 1<=u,v<=n.
Output Format:
Minimum number of friends who need to sacrifice their life for this noble cause along with you.
Code constraints:
1<=n<=1000,1<=n<=1000
Sample Case:
Input:
3 3
1 2
1 3
3 2
Output:
0
Hey guys, this is the question i faced in Online test. Can someone explain question more detail and give a hint for the approach to solve this problem.