1048. Count Strongly Connected Components

MediumGraphsSCCDFSGraph

Given a directed graph with n nodes and edges, return the number of strongly connected components. The input is JSON {n, edges}.

Input: JSON {n, edges}.

Output: Integer — the number of SCCs.

Examples

Example 1
Input: {"n":5,"edges":[[0,1],[1,2],[2,0],[1,3],[3,4]]}
Output: 3
Explanation: {0,1,2},{3},{4}.
Example 2
Input: {"n":1,"edges":[]}
Output: 1
Explanation: Single node.
Example 3
Input: {"n":3,"edges":[[0,1],[1,2],[2,0]]}
Output: 1
Explanation: One SCC.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →