# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20250 | hongjun7 | Cactus? Not cactus? (kriii1_C) | C++14 | 115 ms | 27 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |