We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 013a4ab commit 46d0e7bCopy full SHA for 46d0e7b
CodeChef_problems/Zombies_and_Magic.cpp
@@ -0,0 +1,50 @@
1
+#include<bits/stdc++.h>
2
+#define ll long long
3
+#define N 100000
4
+using namespace std;
5
+
6
+vector<ll>adj[N];
7
+vector<ll>vis(N);
8
+void dfs(ll curr)
9
+{
10
+ vis[curr]=1;
11
+ for(auto neb:adj[curr])
12
+ {
13
+ if(vis[neb]==0)
14
+ dfs(neb);
15
+ }
16
+}
17
+int main()
18
19
+ ll n,m;
20
+ cin>>n>>m;
21
+ ll z;
22
+ cin>>z;
23
+ for(ll i=0;i<m;i++)
24
25
+ ll u,v;
26
+ cin>>u>>v;
27
+ adj[u].push_back(v);
28
+ adj[v].push_back(u);
29
30
+ for(ll i=0;i<n;i++)
31
+ vis[i]=0;
32
+ vis[z]=1;
33
+ if(z==0)dfs(1);
34
+ else
35
+ dfs(0);
36
+ ll flag=0;
37
38
39
+ if(!vis[i])
40
41
+ flag=1;
42
+ break;
43
44
45
+ if(flag==0)
46
+ cout<<"yes\n";
47
48
+ cout<<"no\n";
49
50
0 commit comments