Evacuation
Time limit1sMemory limit128 MB
Find the minimum number of directed edges to remove so that no path of length at most three remains from node 1 to node n.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Minimum spanning tree, Implementation
- Solved
- No attempts yet
Problem
Because of a growing terrorist threat, the Agency for Defending Byteland (ADB) has decided to prepare a plan of action for the case of an attack. The agency's key concern is making sure that the king of Byteland can be evacuated quickly whenever a bombing takes place.
The royal palace stands next to one of the junctions in the capital of Byteland, and a shelter stands next to another junction; in case of danger the king must be moved there at once. The ADB has an exact road map of the capital, made up of junctions joined by one-way streets.
An evacuation route counts as quick if it uses at most three streets. When a bombing hits a street, that street becomes impassable for the royal convoy. The ADB wants to know the minimum number of streets that must be bombed so that the king is left with no quick evacuation route at all.
Input
The first line contains two integers and (, ): the number of junctions and the number of streets in the capital. Junctions are numbered from to ; the royal palace is next to junction and the shelter is next to junction .
Each of the next lines contains two integers and (, ), describing a one-way street that runs from junction to junction . For every ordered pair of junctions there is at most one street going from the first one to the second one.
Output
Print a single integer: the minimum number of streets that must be bombed so that the king has no evacuation route using at most three streets.
Hint

In the picture above it is enough to bomb the streets and (shown crossed out) so that no quick evacuation route remains.