Dumbo the elephant has a huge labyrinth with
We can describe this as a game for two players. The mouse tries to maximize the number of Dumbo's moves. The Dumbo tries to win in minimal number of moves. The first player is Dumbo. On his turn, he may clean one dirty passage of the labyrinth or block one passage. It doesn't matter if the blocked passage is clean or not. He cannot unblock a passage. He may, however, choose to do nothing. Turns in which Dumbo decides to do nothing do not count as moves. When it is the mouse's turn, the mouse will choose a clean unblocked passage and run to the adjacent room down that passage. If there is no such passage leading from the mouse's current room, the mouse won't move.
Initially, all the passages are clean, the mouse is in room
Input
Integers
In each line,
Note that the input size is large.
Constraints
Subtask 1 (20%)
Subtask 2 (25%)
- It is guaranteed that a passage between rooms
and exists.
Subtask 3 (20%)
Subtask 4 (35%)
- no additional constraints
Output
Your program should print the number of Dumbo's moves.
Sample Input
10 1 4
1 2
2 3
2 4
3 9
3 5
4 7
4 6
6 8
7 10
Sample Output
4
Explanation
One possible scenario:
- Dumbo blocks passage between rooms 4 and 7.
- Mouse moves to room 6. The passage between rooms 4 and 6 is now dirty.
- Dumbo blocks the passage between rooms 6 and 8.
- Mouse cannot move.
- Dumbo cleans the passage between rooms 4 and 6.
- Mouse moves to room 4. The passage between rooms 4 and 6 is dirty.
- Dumbo blocks the passage between rooms 2 and 3.
- Mouse moves to room 2. The passage between rooms 2 and 4 is dirty.
- Dumbo doesn't do anything.
- Mouse can only move to room 1 and gets caught into a trap.
Dumbo made 4 moves.
Comments