Strongly Connected Pieces
Count the strongly connected components of a directed graph (maximal sets where every node reaches every other).
Input: the first line has N and M; each of the next M lines has a directed edge u → v.
Output: the number of SCCs.
Constraints:
- 1 ≤ N ≤ 104
- 0 ≤ M ≤ 2×104
Sample Tests
Input 1
5 5 1 2 2 3 3 1 3 4 4 5
Output 1
3
Input 2
3 0
Output 2
3
Discussion (opens after you solve — no spoilers before)
No comments yet.