#include <bits/stdc++.h>
using namespace std;
array<int, 2> g[1<<20];
int N, p, j;
struct Solver {
int e[1<<20], d[1<<20] = {};
int maxDeg = 0, cycle = -1, rem = -1;
int find(int u){
return e[u] < 0 ? u : e[u] = find(e[u]);
}
void add(int u, int v) {
if(u == rem || v == rem || maxDeg > 2) return;
maxDeg = max({maxDeg, ++d[u], ++d[v]});
if((u = find(u)) == (v = find(v))) {
cycle = cycle >= 0 ? N : u;
} else {
if(e[u] > e[v]) swap(u, v);
e[u] += e[v], e[v] = u;
}
}
int get() {
if(maxDeg > 2) return 0;
return cycle >= 0 ? e[cycle] : N;
}
} s[5];
void Init(int N_) {
N = N_;
s[0].get();
for(int i = 0; i < 5; i++)
fill(s[i].e, s[i].e+N, -1);
}
void Link(int A, int B) {
if(!p) {
s[0].add(A, B);
if(s[0].maxDeg > 2) {
for(int i = 0; i < N; i++)
if(s[0].d[i] > 2) s[p=1].rem = i;
for(int k = 0; k < j; k++)
for(int i : {0, 1})
if(g[k][i] == s[1].rem) s[++p].rem = g[k][!i];
for(int i = 1; i < 5; i++)
for(int k = 0; k < j; k++)
s[i].add(g[k][0], g[k][1]);
}
g[j++] = {A, B};
} else
for(int i = 1; i < 5; i++)
s[i].add(A, B);
}
int CountCritical() {
int res = 0;
if(p)
for(int i = 1; i < 5; i++)
res += s[i].get() > 0;
else res = abs(s[0].get());
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20860 KB |
Output is correct |
2 |
Incorrect |
9 ms |
21036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
39400 KB |
Output is correct |
2 |
Correct |
342 ms |
43124 KB |
Output is correct |
3 |
Correct |
280 ms |
45000 KB |
Output is correct |
4 |
Correct |
330 ms |
52596 KB |
Output is correct |
5 |
Correct |
404 ms |
52652 KB |
Output is correct |
6 |
Correct |
319 ms |
52248 KB |
Output is correct |
7 |
Correct |
262 ms |
44980 KB |
Output is correct |
8 |
Correct |
617 ms |
48620 KB |
Output is correct |
9 |
Incorrect |
592 ms |
51408 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20860 KB |
Output is correct |
2 |
Incorrect |
9 ms |
21036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20860 KB |
Output is correct |
2 |
Incorrect |
9 ms |
21036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
20860 KB |
Output is correct |
2 |
Incorrect |
9 ms |
21036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |