#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define X first
#define Y second
const ll MAXN = 1e6 + 10;
const ll MAXC = 5;
int n, mx[MAXC], par[MAXC][MAXN], ig[MAXN], deg[MAXC][MAXN], sz[MAXC][MAXN],
cyc_cnt[MAXC], cyc_sz[MAXC], cmp = 1;
bool deg_ex;
vector<int> poss, adj[MAXN];
vector<pll> edges;
int find(int ind, int v) {
return par[ind][v] == v ? v : par[ind][v] = find(ind, par[ind][v]);
}
inline void unite(int ind, int u, int v) {
if (u == ig[ind] || v == ig[ind]) return;
deg[ind][u]++;
deg[ind][v]++;
mx[ind] = max(mx[ind], deg[ind][u]);
mx[ind] = max(mx[ind], deg[ind][v]);
u = find(ind, u), v = find(ind, v);
if (u == v) {
cyc_cnt[ind]++;
cyc_sz[ind] += sz[ind][u];
return;
}
par[ind][v] = u;
sz[ind][u] += sz[ind][v];
}
inline void init(int ind, int v = 0) {
ig[ind] = v;
for (int i = 1; i <= n; i++) {
par[ind][i] = i;
sz[ind][i] = 0;
}
mx[ind] = 0;
cyc_cnt[ind] = 0;
cyc_sz[ind] = 0;
for (auto [u, v] : edges)
unite(ind, u, v);
}
void Init(int N_) {
n = N_;
deg_ex = false;
init(0);
}
inline void check(int v) {
if (deg_ex) return;
if (int(adj[v].size()) > 2) {
deg_ex = true;
poss.push_back(v);
for (int u : adj[v]) poss.push_back(u);
cmp = poss.size();
for (int i = 0; i < cmp; i++)
init(i, poss[i]);
}
}
void Link(int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
check(u);
check(v);
for (int i = 0; i < cmp; i++)
unite(i, u, v);
edges.push_back({u, v});
}
int CountCritical() {
if (!deg_ex) {
if (cyc_cnt[0] == 0) return n;
else if (cyc_cnt[0] == 1) return cyc_sz[0];
return 0;
}
int ans = 0;
for (int i = 0; i < cmp; i++)
if (mx[i] <= 2 && cyc_cnt[i] == 0)
ans++;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23712 KB |
Output is correct |
2 |
Incorrect |
14 ms |
24308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
57112 KB |
Output is correct |
2 |
Incorrect |
989 ms |
103404 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23712 KB |
Output is correct |
2 |
Incorrect |
14 ms |
24308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23712 KB |
Output is correct |
2 |
Incorrect |
14 ms |
24308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23712 KB |
Output is correct |
2 |
Incorrect |
14 ms |
24308 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |