# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119777 | ahmad_salah | Parachute rings (IOI12_rings) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
const int M = 1e6;
int n, ends;
vector<int> adj[M];
bool v[M], ok;
void dfs(int node, int forb) {
if (!v[node]) {
v[node] = 1;
int cnt = 0;
for (int x : adj[node])
if (x != forb)
cnt++;
if (cnt > 2) {
ok = false;
return;
}
if (!cnt)
ends = 2;
else if (cnt == 1)
ends++;
for (int x : adj[node])
if (x != forb)
dfs(x, forb);
}
}
void Init(int N) { n = N; }
void Link(int a, int b) {
adj[a].push_back(b);
adj[b].push_back(a);
}
int CountCritical() {
int ans = 0;
for (int i = 0; i < n; i++) {
memset(v, 0, sizeof v);
ok = true;
ends = 0;
for (int j = 0; j < n; j++)
if (!v[j] && i != j)
dfs(j, i);
ans += (ok && ends == 2);
}
return ans;
}