-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph_Pillar_Vertice.cpp
97 lines (89 loc) · 2.32 KB
/
Graph_Pillar_Vertice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <bits/stdc++.h>
using namespace std;
#define V 13
vector<vector<int> > adjacent_list(V);
vector<bool> notVisited(V, true);
void BFS(int n)
{
queue<int> qu;
qu.push(n);
int s;
while(!qu.empty())
{
s = qu.front();
qu.pop();
for(auto v : adjacent_list[s])
{
if(notVisited[v])
{
qu.push(v);
notVisited[v] = false;
}
}
}
}
int main()
{
int graph[V][V] = {{0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}};
for(int i=0; i<V; i++)
{
for(int j=0; j<V; j++)
{
if(graph[i][j])
{
adjacent_list[i].push_back(j);
}
}
}
for(int i = 0; i < adjacent_list.size(); i++)
{
for(int j = 0; j < adjacent_list[i].size(); j++)
{
cout << adjacent_list[i][j] << " ";
}
cout << endl;
}
int stp{0}, count{0};
for(int i=0; i<V; i++)
{
if(notVisited[i])
{
stp++;
notVisited[i] = false;
BFS(i);
}
}
cout << "\nPillar Vertices\n";
for(int i=0; i<V; i++)
{
notVisited.clear();
notVisited.resize(V+1, true);
count = 0;
notVisited[i] = false;
for(int j=0; j<V; j++)
{
if(notVisited[j])
{
count++;
notVisited[j] = false;
BFS(j);
}
}
if(count > stp)
{
cout << i << " ";
}
}
}