# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080665 | asdasdqwer | Parachute rings (IOI12_rings) | C++14 | 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;
#include "rings.h"
vector<vector<int>> g;
vector<int> deg;
int n;
void Init(int N) {
g.resize(N);
deg.assign(N, 0);
n = N;
}
void Link(int A, int B) {
g[A].push_back(B);
g[B].push_back(A);
}
bool check(int node) {
for (int i=0;i<n;i++) {
deg[i] = 0;
}
vector<bool> vis(n, false);
vis[node] = true;
vector<int> tmp;
function<void(int)>dfs=[&](int nd) {
tmp.push_back(nd);
vis[nd]=true;
for (int x:g[nd]) {
if (!vis[x]) {
dfs(x);
}
if (x != node) {
deg[x]++;
}
}
};
vector<bool> vis2(n, false);
vis2[node] = true;
function<bool(int)> dfs2=[&](int nd)->bool {
if (nd == -1) return true;
vis2[nd]=true;
if (deg[nd] > 2) return false;
int nxt = -1;
for (int x:g[nd]) {
if (x != node && !vis2[x]) {
if (nxt == -1) nxt = x;
else return false;
}
}
return dfs2(nxt);
};
for (int x=0;x<n;x++) {
if (!vis[x]) {
dfs(x);
int cand = -1;
for (int y:tmp) {
if (deg[y] <= 1) {
cand = y;
}
}
if (cand == -1) {
return false;
}
if (!dfs2(cand)) return false;
tmp.clear();
}
}
return true;
}
int CountCritical() {
int res = 0;
for (int i=0;i<n;i++) {
if (check(i))res++;
}
return res;
}