ALG-H011HardGraphs
Strongly Connected Zones
In a directed graph, count maximal groups where every node can reach every other node within the same group. Isolated nodes each form a group.
Contract
input n: integer
input edges: integer[][]
return integer
Constraints
- • n >= 1
- • 0 <= node id < n
Examples
Example 1
n = 5
edges = [[0, 1], [1, 2], [2, 0], [2, 3], [3, 4], [4, 3]]
→ 2
Example 2
n = 3
edges = []
→ 3
5 judge tests (2 shown above). Target complexity: O(V+E).