Reverse the graph
Very easy
Execution time limit is 6 seconds
Runtime memory usage limit is 256 megabytes
A directed graph with vertices and edges is given, with vertices numbered from to . Find the minimum number of edges that need to be reversed so that there exists at least one path from vertex to vertex .
Input
The first line contains two integers and — the number of vertices and edges in the graph. Each of the following lines contains two integers and , indicating that the -th directed edge goes from vertex to vertex .
Output
Print the minimum number of edges that need to be reversed. If it is not possible to obtain a path from vertex to vertex , print .
Examples
Input #1
Answer #1
Submissions 3K
Acceptance rate 30%