# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
20250 | 2016-08-09T02:01:37 Z | hongjun7 | Cactus? Not cactus? (kriii1_C) | C++14 | 115 ms | 27 KB |
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; #define MAXN 100005 int n, m, d[MAXN], res, up[MAXN]; vector <int> v[MAXN]; int f(int x, int par) { int cnt = 0, ret = d[x]; up[x] = d[x]; for (auto &y : v[x]) { if (y == par) continue; if (!d[y]) { d[y] = d[x] + 1; int u = f(y, x); ret = min(ret, u); if (u <= d[x]) cnt++; } else { if (d[y] < d[x]) cnt++; up[x] = min(up[x], d[y]); } } if (cnt >= 2) res = 0; ret = min(ret, up[x]); return ret; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); v[x].emplace_back(y); v[y].emplace_back(x); } d[1] = res = 1; f(1, 0); if (res) puts("Cactus"); else puts("Not cactus"); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2 KB | Output is correct |
2 | Correct | 4 ms | 2 KB | Output is correct |
3 | Correct | 5 ms | 3 KB | Output is correct |
4 | Correct | 5 ms | 3 KB | Output is correct |
5 | Correct | 5 ms | 3 KB | Output is correct |
6 | Correct | 5 ms | 3 KB | Output is correct |
7 | Correct | 6 ms | 3 KB | Output is correct |
8 | Correct | 5 ms | 3 KB | Output is correct |
9 | Correct | 6 ms | 3 KB | Output is correct |
10 | Correct | 42 ms | 7 KB | Output is correct |
11 | Correct | 33 ms | 7 KB | Output is correct |
12 | Correct | 38 ms | 11 KB | Output is correct |
13 | Correct | 47 ms | 11 KB | Output is correct |
14 | Correct | 47 ms | 12 KB | Output is correct |
15 | Correct | 50 ms | 15 KB | Output is correct |
16 | Correct | 37 ms | 15 KB | Output is correct |
17 | Correct | 35 ms | 16 KB | Output is correct |
18 | Correct | 65 ms | 20 KB | Output is correct |
19 | Correct | 115 ms | 22 KB | Output is correct |
20 | Correct | 44 ms | 22 KB | Output is correct |
21 | Correct | 66 ms | 22 KB | Output is correct |
22 | Correct | 58 ms | 23 KB | Output is correct |
23 | Correct | 4 ms | 23 KB | Output is correct |
24 | Correct | 3 ms | 23 KB | Output is correct |
25 | Correct | 8 ms | 23 KB | Output is correct |
26 | Correct | 61 ms | 23 KB | Output is correct |
27 | Correct | 24 ms | 23 KB | Output is correct |
28 | Correct | 47 ms | 23 KB | Output is correct |
29 | Correct | 50 ms | 23 KB | Output is correct |
30 | Correct | 43 ms | 23 KB | Output is correct |
31 | Correct | 49 ms | 23 KB | Output is correct |
32 | Correct | 78 ms | 25 KB | Output is correct |
33 | Correct | 63 ms | 26 KB | Output is correct |
34 | Correct | 55 ms | 27 KB | Output is correct |