Question: Strongly Connected Components: Need to create a C++ program,need help. Description: A strongly connected component (SCC) of a directed graph G = (V, E) is
Strongly Connected Components:
Need to create a C++ program,need help.
Description: A strongly connected component (SCC) of a directed graph G = (V, E) is defined as a maximal set of vertices C ? V such that for every pair of vertices u and v in C, the two vertices are reachable from each other. In this lab assignment, you are asked to decompose a given directed graph G = (V, E) into a collection of SCCs.
Input: The input will have the following format. The first integer refers to the number of vertices, |V |. The second integer is the number of edges, |E|. Vertices are indexed by 0, 1, ..., |V | ? 1. Then, two numbers u v appearing in each line means an edge (u, v). See the example given below.
Output: Output the SCC ID of every vertex. A SCCs ID is defined as the smallest index of any vertex in the SCC. In other words, you have to output, for each vertex v, the ID of the unique SCC the vertex v belongs to. You must output the ID for each vertex, considering vertices in the order of 0, 1, ..., |V | ? 1.
Examples of input and output
Input
8
13
0 1
1 2
1 4
1 5
2 3
2 6
3 2
3 7
4 0
4 5
5 6
6 5
6 7
Output for problem 2
0
0
2
2
0
5
5
7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
