Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Count Strongly Connected Components (Kosaraju’s Algorithm)
HARD
40 mins
24 upvotes
Graph
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Graph
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Count Strongly Connected Components (Kosaraju’s Algorithm)

Contributed by
Vishal Modani
Hard
yellow-spark
0/120
Avg time to solve 40 mins
Success Rate 65 %
Share
24 upvotes

Problem Statement

You are given an unweighted directed graph having 'V' vertices and 'E' edges. Your task is to count the number of strongly connected components (SCCs) present in the graph.

A directed graph is said to be strongly connected if every vertex is reachable from every other vertex. The strongly connected components of a graph are the subgraphs which are themselves strongly connected.

Note :
Use zero-based indexing for the vertices.

The given graph doesn’t contain any self-loops.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
1
5 6
0 1
1 2
1 4
2 3
3 2
4 0
Sample Output 1 :
2
Explanation of sample input 1 :
For the first test case, the graph is shown below. There are two SCCs in the graph, which are enclosed in the boxes as shown in the image below.

Sample Testcase 1 - Graph

Sample Input 2 :
2
1 0
4 4
0 1
1 2
2 3
3 1
Sample Output 2 :
1
2
Reset Code
Full screen
Auto
copy-code
Console