#include <stdio.h>
struct al{
int e,nx;
}a[200010];
int st[100010],chk[100010],p[100010],cycle[100010],t;
void make_al(int s,int e){a[++t].nx=st[s],a[t].e=e,st[s]=t;}
void get_cycle(int s,int x){
++cycle[x];
for(;;){
++cycle[s];
s=p[s];
if(s==x)return;
}
}
void DFS(int s){
int i;
chk[s]=1;
for(i=st[s];i;i=a[i].nx)if(chk[a[i].e]){
if(p[s]==a[i].e)continue;
get_cycle(s,a[i].e);
}
for(i=st[s];i;i=a[i].nx)if(!chk[a[i].e]){
p[a[i].e]=s;
DFS(a[i].e);
}
}
int main(){
int i,n,m,s,e;
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i){
scanf("%d%d",&s,&e);
make_al(s,e),make_al(e,s);
}
DFS(1);
for(i=1;i<=n;++i)if(cycle[i]>1){
puts("Not cactus");
return 0;
}
puts("Cactus");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4208 KB |
Output is correct |
2 |
Correct |
0 ms |
4208 KB |
Output is correct |
3 |
Correct |
0 ms |
4208 KB |
Output is correct |
4 |
Correct |
0 ms |
4208 KB |
Output is correct |
5 |
Correct |
0 ms |
4208 KB |
Output is correct |
6 |
Correct |
0 ms |
4208 KB |
Output is correct |
7 |
Correct |
0 ms |
4208 KB |
Output is correct |
8 |
Correct |
2 ms |
4208 KB |
Output is correct |
9 |
Correct |
0 ms |
4208 KB |
Output is correct |
10 |
Correct |
30 ms |
4208 KB |
Output is correct |
11 |
Correct |
16 ms |
4208 KB |
Output is correct |
12 |
Correct |
27 ms |
5668 KB |
Output is correct |
13 |
Correct |
29 ms |
5032 KB |
Output is correct |
14 |
Correct |
25 ms |
4984 KB |
Output is correct |
15 |
Correct |
35 ms |
5056 KB |
Output is correct |
16 |
Correct |
28 ms |
5288 KB |
Output is correct |
17 |
Correct |
15 ms |
5800 KB |
Output is correct |
18 |
Correct |
36 ms |
5856 KB |
Output is correct |
19 |
Correct |
48 ms |
6836 KB |
Output is correct |
20 |
Correct |
28 ms |
5048 KB |
Output is correct |
21 |
Correct |
35 ms |
4968 KB |
Output is correct |
22 |
Correct |
30 ms |
6356 KB |
Output is correct |
23 |
Correct |
0 ms |
4208 KB |
Output is correct |
24 |
Correct |
0 ms |
4208 KB |
Output is correct |
25 |
Correct |
0 ms |
4316 KB |
Output is correct |
26 |
Correct |
39 ms |
4208 KB |
Output is correct |
27 |
Correct |
13 ms |
4208 KB |
Output is correct |
28 |
Correct |
34 ms |
4208 KB |
Output is correct |
29 |
Correct |
37 ms |
4208 KB |
Output is correct |
30 |
Correct |
17 ms |
4208 KB |
Output is correct |
31 |
Correct |
28 ms |
4208 KB |
Output is correct |
32 |
Correct |
32 ms |
4208 KB |
Output is correct |
33 |
Correct |
25 ms |
4208 KB |
Output is correct |
34 |
Correct |
40 ms |
4208 KB |
Output is correct |