forked from as-square/GRAPH-THEORY
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsf.cpp
More file actions
45 lines (38 loc) · 672 Bytes
/
dsf.cpp
File metadata and controls
45 lines (38 loc) · 672 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
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> g[N];
bool vis[N];
void dfs(int a){
for(auto elm : g[a])
{
if (!vis[elm])
{
vis[elm]=1;
dfs(elm);
}
}
}
int main() {
int n,m;
cin>>n>>m;
for (int i=0; i <n; i++)
{
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i=1;i<=5;i++)
{
if (!vis[i])
{
dfs(i);
}
}
for (int i = 0; i < 6; i++)
{
cout<<vis[i]<<"\n";
}
return 0;
}