#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");
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
4 ms |
4560 KB |
Output is correct |
9 |
Correct |
0 ms |
4560 KB |
Output is correct |
10 |
Correct |
40 ms |
7332 KB |
Output is correct |
11 |
Correct |
28 ms |
7180 KB |
Output is correct |
12 |
Correct |
36 ms |
8532 KB |
Output is correct |
13 |
Correct |
44 ms |
7832 KB |
Output is correct |
14 |
Correct |
44 ms |
7640 KB |
Output is correct |
15 |
Correct |
40 ms |
9448 KB |
Output is correct |
16 |
Correct |
36 ms |
7760 KB |
Output is correct |
17 |
Correct |
24 ms |
8600 KB |
Output is correct |
18 |
Correct |
64 ms |
10672 KB |
Output is correct |
19 |
Correct |
68 ms |
11464 KB |
Output is correct |
20 |
Correct |
28 ms |
8076 KB |
Output is correct |
21 |
Correct |
64 ms |
7816 KB |
Output is correct |
22 |
Correct |
48 ms |
9868 KB |
Output is correct |
23 |
Correct |
0 ms |
4428 KB |
Output is correct |
24 |
Correct |
0 ms |
4428 KB |
Output is correct |
25 |
Correct |
4 ms |
4924 KB |
Output is correct |
26 |
Correct |
64 ms |
7200 KB |
Output is correct |
27 |
Correct |
12 ms |
5484 KB |
Output is correct |
28 |
Correct |
36 ms |
6804 KB |
Output is correct |
29 |
Correct |
48 ms |
6804 KB |
Output is correct |
30 |
Correct |
40 ms |
6936 KB |
Output is correct |
31 |
Correct |
44 ms |
6804 KB |
Output is correct |
32 |
Correct |
52 ms |
7200 KB |
Output is correct |
33 |
Correct |
48 ms |
7200 KB |
Output is correct |
34 |
Correct |
48 ms |
7200 KB |
Output is correct |