Description
Given a directed graph with n nodes (0..n-1) and a list of directed edges, return the number of strongly connected components.
Examples
Input:
n = 5, edges = [[0,1],[1,2],[2,0],[3,4]]Output:
3Explanation:
Strongly connected components are {0,1,2}, {3}, and {4}, giving a count of 3.
Input:
n = 1, edges = []Output:
1Explanation:
A single node is its own strongly connected component, so the count is 1.
Input:
n = 3, edges = [[0,1],[1,2]]Output:
3Explanation:
The DAG 0->1->2 has three trivial single-node SCCs.
Constraints
- •
1 ≤ n ≤ 1000 - •
0 ≤ edges.length ≤ 5000