Strong connectivity
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
A strongly connected component in a directed graph is a set of vertices such that there is a path from any vertex to any other vertex in the set. Moreover, there is no larger set with this property containing this set.
Given a directed graph. Find the number of strongly connected components.
Input
The first line contains two integers and — the number of vertices and edges in the graph, respectively. The next lines describe the edges: the -th line contains two integers and — the start and the end of the -th edge respectively. It is guaranteed that the graph has no loops or multiple edges.
Output
Print the number of strongly connected components in the graph.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 1K
Acceptance rate 57%