#include<stdio.h>
#include<vector>
using namespace std;
vector<int> edge[100000];
vector<int> now;
bool check[100000]={0};
bool check_cycle[100000]={0};
bool ans=false;
int distime[100000]={0},deltime[100000]={0},time=0;
void dfs(int a,int par){
check[a]=true;
distime[a]=time++;
now.push_back(a);
int i,j;
for(i=0;i<edge[a].size();i++){
if(check[edge[a][i]] && edge[a][i]!=par && distime[edge[a][i]]<distime[a]){
for(j=now.size()-1;j>=0;j--){
if(check_cycle[now[j]]){
ans=true;
return;
}
check_cycle[now[j]]=true;
if(now[j]==edge[a][i]) break;
}
}
else if(!check[edge[a][i]]){
dfs(edge[a][i],a);
if(ans) return;
}
}
deltime[a]=time++;
now.pop_back();
}
int main()
{
int i,n,m,a,b;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){
scanf("%d%d",&a,&b);
edge[a-1].push_back(b-1);
edge[b-1].push_back(a-1);
}
dfs(0,0);
if(ans) printf("Not cactus");
else printf("Cactus");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4528 KB |
Output is correct |
2 |
Correct |
0 ms |
4528 KB |
Output is correct |
3 |
Correct |
0 ms |
4660 KB |
Output is correct |
4 |
Correct |
0 ms |
4660 KB |
Output is correct |
5 |
Correct |
0 ms |
4528 KB |
Output is correct |
6 |
Correct |
0 ms |
4660 KB |
Output is correct |
7 |
Correct |
4 ms |
4660 KB |
Output is correct |
8 |
Correct |
4 ms |
4660 KB |
Output is correct |
9 |
Correct |
4 ms |
4660 KB |
Output is correct |
10 |
Correct |
28 ms |
7432 KB |
Output is correct |
11 |
Correct |
28 ms |
7280 KB |
Output is correct |
12 |
Correct |
40 ms |
8976 KB |
Output is correct |
13 |
Correct |
48 ms |
8100 KB |
Output is correct |
14 |
Correct |
40 ms |
7864 KB |
Output is correct |
15 |
Correct |
56 ms |
9860 KB |
Output is correct |
16 |
Correct |
32 ms |
8300 KB |
Output is correct |
17 |
Correct |
40 ms |
9056 KB |
Output is correct |
18 |
Correct |
52 ms |
11392 KB |
Output is correct |
19 |
Correct |
76 ms |
12172 KB |
Output is correct |
20 |
Correct |
36 ms |
8512 KB |
Output is correct |
21 |
Correct |
60 ms |
8064 KB |
Output is correct |
22 |
Correct |
44 ms |
10252 KB |
Output is correct |
23 |
Correct |
0 ms |
4528 KB |
Output is correct |
24 |
Correct |
0 ms |
4528 KB |
Output is correct |
25 |
Correct |
4 ms |
5024 KB |
Output is correct |
26 |
Correct |
52 ms |
7300 KB |
Output is correct |
27 |
Correct |
16 ms |
5584 KB |
Output is correct |
28 |
Correct |
32 ms |
6904 KB |
Output is correct |
29 |
Correct |
40 ms |
6904 KB |
Output is correct |
30 |
Correct |
44 ms |
7036 KB |
Output is correct |
31 |
Correct |
32 ms |
6904 KB |
Output is correct |
32 |
Correct |
52 ms |
7300 KB |
Output is correct |
33 |
Correct |
56 ms |
7300 KB |
Output is correct |
34 |
Correct |
44 ms |
7300 KB |
Output is correct |