Given a directed graph, determine whether every vertex can reach every other vertex. Return true if the graph is strongly connected; otherwise return false. Pattern focus: SCC. This can be checked by counting SCCs or by running reachability on both the graph and its reverse.
n = number of vertices, edges = directed edges [u, v]
true if the graph is strongly connected, otherwise false
Example 1:
Input:
n = 3 edges = [[1,2],[2,3],[3,1]]
Output:
true
Explanation:
Every vertex can reach every other vertex.
Example 2:
Input:
n = 3 edges = [[1,2],[2,3]]
Output:
false
Explanation:
Vertex 3 cannot reach vertex 1, so the graph is not strongly connected.
Example 3:
Input:
n = 1 edges = []
Output:
true
Explanation:
A single-vertex graph is strongly connected.