Code : All connected components
1. V is the number of vertices present in graph G and vertices are numbered from 0 to V-1.
2. E is the number of edges present in graph G.
3. You need to take input in main and create a function which should return all the connected components. And then print them in the main, not inside function.
The first line of input contains two integers, that denote the value of V and E.
Each of the following E lines contains two space separated integers, that denote that there exists an edge between vertex a and b.
Print different components in new line. And each component should be printed in increasing order of vertices (separated by space). Order of different components doesn't matter.
0 <= V <= 1000
0 <= E <= (V * (V - 1)) / 2
0 <= a <= V - 1
0 <= b <= V - 1
4 2
0 1
2 3
0 1
2 3
4 3
0 1
1 3
0 3
0 1 3
2
#include <iostream>using namespace std;
int main() { // Write your code here}
Comments
Post a Comment