-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·53 lines (42 loc) · 893 Bytes
/
Copy pathsol.cpp
File metadata and controls
executable file
·53 lines (42 loc) · 893 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>> adj(n + 1, vector<int>());
vector<bool> visited(n + 1, false);
for (int i = 0; i < m; ++i)
{
int s, t;
cin >> s >> t;
adj[s].push_back(t);
adj[t].push_back(s);
}
queue<int> Q;
Q.push(1);
visited[1] = true;
while (!Q.empty())
{
int s = Q.front();
Q.pop();
for (int t : adj[s])
{
if (!visited[t])
{
visited[t] = 1;
Q.push(t);
}
}
}
bool fully_connected = true;
for (int i = 1; i <= n; ++i)
if (!visited[i])
{
fully_connected = false;
cout << i << endl;
}
if (fully_connected)
cout << "Connected" << endl;
return 0;
}