#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int par[100010], num[100100], C;
bool chk[100010], ck;
vector<int>E[100010];
int n;
void DFS(int a, int p){
par[a] = p;
num[a] = ++C;
int i, x;
for (i = 0; i < E[a].size(); i++){
if (E[a][i] == p)continue;
if (par[E[a][i]]){
if (num[E[a][i]] > num[a])continue;
x = a;
while (x != E[a][i]){
ck |= chk[x];
chk[x] = true;
x = par[x];
}
ck |= chk[x];
chk[x] = true;
if (ck)return;
}
else DFS(E[a][i], a);
if (ck)return;
}
}
int main(){
int i, a, b, m;
scanf("%d%d", &n, &m);
while (m--){
scanf("%d%d", &a, &b);
E[a].push_back(b);
E[b].push_back(a);
}
DFS(1, 1);
printf(ck ? "Not Cactus\n" : "Cactus\n");
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4428 KB |
Output is correct |
2 |
Correct |
0 ms |
4428 KB |
Output is correct |
3 |
Correct |
0 ms |
4560 KB |
Output is correct |
4 |
Correct |
4 ms |
4428 KB |
Output is correct |
5 |
Correct |
0 ms |
4428 KB |
Output is correct |
6 |
Correct |
4 ms |
4560 KB |
Output is correct |
7 |
Correct |
4 ms |
4560 KB |
Output is correct |
8 |
Correct |
0 ms |
4560 KB |
Output is correct |
9 |
Correct |
0 ms |
4560 KB |
Output is correct |
10 |
Correct |
32 ms |
7332 KB |
Output is correct |
11 |
Correct |
32 ms |
7180 KB |
Output is correct |
12 |
Correct |
44 ms |
8532 KB |
Output is correct |
13 |
Correct |
56 ms |
7836 KB |
Output is correct |
14 |
Correct |
40 ms |
7636 KB |
Output is correct |
15 |
Correct |
36 ms |
9448 KB |
Output is correct |
16 |
Correct |
44 ms |
7764 KB |
Output is correct |
17 |
Correct |
32 ms |
8596 KB |
Output is correct |
18 |
Correct |
64 ms |
10676 KB |
Output is correct |
19 |
Correct |
72 ms |
11468 KB |
Output is correct |
20 |
Correct |
32 ms |
8084 KB |
Output is correct |
21 |
Correct |
60 ms |
7824 KB |
Output is correct |
22 |
Correct |
52 ms |
9860 KB |
Output is correct |
23 |
Incorrect |
0 ms |
4428 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |