#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
vector <int> A[100001];
int N, M, S[100001], top, check[100001], cycle[100001];
void input(void)
{
int i, x, y;
scanf("%d %d",&N,&M);
for(i=1 ; i<=M ; i++)
{
scanf("%d %d",&x,&y);
A[x].push_back(y);
A[y].push_back(x);
}
}
void process(int now, int prev)
{
int i, j, k;
j=A[now].size();
for(i=0 ; i<j ; i++)
if(A[now][i]!=prev)
{
if(check[A[now][i]])
for(k=check[A[now][i]] ; k<=top ; k++)
{
if(cycle[S[k]])
{
printf("Not cactus");
exit(0);
}
else
cycle[S[k]]=1;
}
else
{
S[++top]=A[now][i];
check[A[now][i]]=top;
process(A[now][i],now);
top--;
}
}
}
int main(void)
{
input();
S[++top]=1;
check[1]=top;
process(1,0);
top--;
printf("Cactus");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4720 KB |
Output is correct |
2 |
Correct |
0 ms |
4720 KB |
Output is correct |
3 |
Correct |
0 ms |
4852 KB |
Output is correct |
4 |
Correct |
4 ms |
4720 KB |
Output is correct |
5 |
Correct |
0 ms |
4720 KB |
Output is correct |
6 |
Correct |
4 ms |
4852 KB |
Output is correct |
7 |
Correct |
4 ms |
4852 KB |
Output is correct |
8 |
Correct |
4 ms |
4852 KB |
Output is correct |
9 |
Correct |
0 ms |
4852 KB |
Output is correct |
10 |
Correct |
36 ms |
7624 KB |
Output is correct |
11 |
Correct |
32 ms |
7472 KB |
Output is correct |
12 |
Correct |
32 ms |
8824 KB |
Output is correct |
13 |
Correct |
36 ms |
8124 KB |
Output is correct |
14 |
Correct |
52 ms |
7928 KB |
Output is correct |
15 |
Correct |
52 ms |
9740 KB |
Output is correct |
16 |
Correct |
32 ms |
8056 KB |
Output is correct |
17 |
Correct |
24 ms |
8892 KB |
Output is correct |
18 |
Correct |
60 ms |
10968 KB |
Output is correct |
19 |
Correct |
60 ms |
11760 KB |
Output is correct |
20 |
Correct |
36 ms |
8372 KB |
Output is correct |
21 |
Correct |
44 ms |
8108 KB |
Output is correct |
22 |
Correct |
48 ms |
10156 KB |
Output is correct |
23 |
Correct |
0 ms |
4720 KB |
Output is correct |
24 |
Correct |
0 ms |
4720 KB |
Output is correct |
25 |
Correct |
4 ms |
5212 KB |
Output is correct |
26 |
Correct |
40 ms |
7492 KB |
Output is correct |
27 |
Correct |
24 ms |
5776 KB |
Output is correct |
28 |
Correct |
40 ms |
7096 KB |
Output is correct |
29 |
Correct |
40 ms |
7096 KB |
Output is correct |
30 |
Correct |
32 ms |
7228 KB |
Output is correct |
31 |
Correct |
44 ms |
7096 KB |
Output is correct |
32 |
Correct |
56 ms |
7492 KB |
Output is correct |
33 |
Correct |
48 ms |
7492 KB |
Output is correct |
34 |
Correct |
56 ms |
7492 KB |
Output is correct |