#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include "grader.h"
using namespace std;
#define f first
#define s second
int n, cycsz;
bool nne;
vector<int> adj[1000005];
vector<pair<int, int>> edges;
struct UnionFind1 {
int rt, par[1000005], deg[1000005];
bool vld;
int find(int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
void merge(int x, int y) {
if (!vld || x == rt || y == rt) return;
int px = find(x), py = find(y);
if (deg[x] == 2 || deg[y] == 2 || px == py) {
vld = false;
return;
}
deg[x]++;
deg[y]++;
par[px] = py;
}
UnionFind1(int root) {
rt = root;
vld = true;
for (int i = 0; i < n; i++) {
par[i] = i;
deg[i] = 0;
}
for (pair<int, int> edge : edges) {
merge(edge.f, edge.s);
}
}
};
int par[1000005], sz[1000005];
vector<UnionFind1> uf;
static int find(int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
static bool merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
sz[x] += sz[y];
par[y] = x;
return true;
}
void Init(int N) {
n = N;
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
int CountCritical() {
if (nne) return 0;
if (!uf.empty()) {
int ans = 0;
for (int i = 0; i < uf.size(); i++) {
ans += uf[i].vld;
}
return ans;
} else if (cycsz) return cycsz;
return n;
}
void Link(int a, int b) {
if (nne) return;
if (!uf.empty()) {
for (int i = 0; i < uf.size(); i++) {
uf[i].merge(a, b);
}
return;
}
edges.push_back({a, b});
adj[a].push_back(b);
adj[b].push_back(a);
if (adj[a].size() < adj[b].size()) swap(a, b);
if (adj[a].size() == 3) {
uf.push_back(UnionFind1(a));
for (int i : adj[a]) {
uf.push_back(UnionFind1(i));
}
return;
}
if (!merge(a, b)) {
if (cycsz) {
nne = true;
return;
}
cycsz = sz[find(a)];
}
}
Compilation message
rings.cpp:5:10: fatal error: grader.h: No such file or directory
5 | #include "grader.h"
| ^~~~~~~~~~
compilation terminated.