#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, m, mx;
vector<int> way[maxn];
pair<int,int> e[maxn];
int cysz, ban[5], bad[5], cyc[5];
int head[5][maxn], sz[5][maxn], deg[5][maxn];
void Init(int _n) {
n = _n;
for(int k=0;k<=4;k++) {
for(int i=1;i<=n;i++) {
head[k][i] = i;
sz[k][i] = 1;
}
}
}
int CountCritical() {
if(mx<=2) {
if(cyc[0]==0) return n;
if(cyc[0]==1) return cysz;
return 0;
}
else {
int res = 0;
for(int i=1;i<=4;i++) res += !bad[i];
return res;
}
}
int findhead(int k, int x) {
if(head[k][x]==x) return x;
return head[k][x] = findhead(k, head[k][x]);
}
void edge(int k, int u, int v) {
if(ban[k]==u || ban[k]==v) return ;
++deg[k][u]; ++deg[k][v];
if(deg[k][u]==3) bad[k] = 1;
if(deg[k][v]==3) bad[k] = 1;
int x = findhead(k,u), y = findhead(k,v);
if(x==y) {
bad[k] = 1;
cyc[k]++;
if(k==0) cysz = sz[k][x];
}
else {
sz[k][y] += sz[k][x];
head[k][x] = y;
}
}
void build(int x) {
ban[1] = x;
for(int i=0;i<3;i++) ban[i+2] = way[x][i];
for(int i=1;i<=m;i++) {
for(int k=1;k<=4;k++) edge(k,e[i].first,e[i].second);
}
}
void Link(int x, int y) {
x++; y++;
way[x].push_back(y); way[y].push_back(x);
e[++m] = {x,y};
edge(0,x,y);
if(mx<=2) {
if(way[x].size()==3) build(x);
else if(way[y].size()==3) build(y);
}
else {
for(int k=1;k<=4;k++) edge(k,x,y);
}
mx = max(mx, (int)way[x].size());
mx = max(mx, (int)way[y].size());
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
24548 KB |
Output is correct |
3 |
Correct |
24 ms |
24616 KB |
Output is correct |
4 |
Correct |
22 ms |
24616 KB |
Output is correct |
5 |
Correct |
24 ms |
24616 KB |
Output is correct |
6 |
Correct |
24 ms |
24616 KB |
Output is correct |
7 |
Correct |
24 ms |
24616 KB |
Output is correct |
8 |
Correct |
24 ms |
24660 KB |
Output is correct |
9 |
Correct |
24 ms |
24700 KB |
Output is correct |
10 |
Correct |
33 ms |
24700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
67064 KB |
Output is correct |
2 |
Correct |
2943 ms |
102640 KB |
Output is correct |
3 |
Execution timed out |
4018 ms |
117636 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
24548 KB |
Output is correct |
3 |
Correct |
24 ms |
24616 KB |
Output is correct |
4 |
Correct |
22 ms |
24616 KB |
Output is correct |
5 |
Correct |
24 ms |
24616 KB |
Output is correct |
6 |
Correct |
24 ms |
24616 KB |
Output is correct |
7 |
Correct |
24 ms |
24616 KB |
Output is correct |
8 |
Correct |
24 ms |
24660 KB |
Output is correct |
9 |
Correct |
24 ms |
24700 KB |
Output is correct |
10 |
Correct |
33 ms |
24700 KB |
Output is correct |
11 |
Correct |
25 ms |
117636 KB |
Output is correct |
12 |
Correct |
39 ms |
117636 KB |
Output is correct |
13 |
Correct |
28 ms |
117636 KB |
Output is correct |
14 |
Correct |
27 ms |
117636 KB |
Output is correct |
15 |
Correct |
28 ms |
117636 KB |
Output is correct |
16 |
Correct |
27 ms |
117636 KB |
Output is correct |
17 |
Correct |
28 ms |
117636 KB |
Output is correct |
18 |
Correct |
30 ms |
117636 KB |
Output is correct |
19 |
Correct |
33 ms |
117636 KB |
Output is correct |
20 |
Correct |
29 ms |
117636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
24548 KB |
Output is correct |
3 |
Correct |
24 ms |
24616 KB |
Output is correct |
4 |
Correct |
22 ms |
24616 KB |
Output is correct |
5 |
Correct |
24 ms |
24616 KB |
Output is correct |
6 |
Correct |
24 ms |
24616 KB |
Output is correct |
7 |
Correct |
24 ms |
24616 KB |
Output is correct |
8 |
Correct |
24 ms |
24660 KB |
Output is correct |
9 |
Correct |
24 ms |
24700 KB |
Output is correct |
10 |
Correct |
33 ms |
24700 KB |
Output is correct |
11 |
Correct |
25 ms |
117636 KB |
Output is correct |
12 |
Correct |
39 ms |
117636 KB |
Output is correct |
13 |
Correct |
28 ms |
117636 KB |
Output is correct |
14 |
Correct |
27 ms |
117636 KB |
Output is correct |
15 |
Correct |
28 ms |
117636 KB |
Output is correct |
16 |
Correct |
27 ms |
117636 KB |
Output is correct |
17 |
Correct |
28 ms |
117636 KB |
Output is correct |
18 |
Correct |
30 ms |
117636 KB |
Output is correct |
19 |
Correct |
33 ms |
117636 KB |
Output is correct |
20 |
Correct |
29 ms |
117636 KB |
Output is correct |
21 |
Correct |
45 ms |
117636 KB |
Output is correct |
22 |
Correct |
81 ms |
117636 KB |
Output is correct |
23 |
Correct |
68 ms |
117636 KB |
Output is correct |
24 |
Correct |
91 ms |
117636 KB |
Output is correct |
25 |
Correct |
44 ms |
117636 KB |
Output is correct |
26 |
Correct |
89 ms |
117636 KB |
Output is correct |
27 |
Correct |
85 ms |
117636 KB |
Output is correct |
28 |
Correct |
109 ms |
117636 KB |
Output is correct |
29 |
Correct |
72 ms |
117636 KB |
Output is correct |
30 |
Correct |
88 ms |
117636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
24548 KB |
Output is correct |
3 |
Correct |
24 ms |
24616 KB |
Output is correct |
4 |
Correct |
22 ms |
24616 KB |
Output is correct |
5 |
Correct |
24 ms |
24616 KB |
Output is correct |
6 |
Correct |
24 ms |
24616 KB |
Output is correct |
7 |
Correct |
24 ms |
24616 KB |
Output is correct |
8 |
Correct |
24 ms |
24660 KB |
Output is correct |
9 |
Correct |
24 ms |
24700 KB |
Output is correct |
10 |
Correct |
33 ms |
24700 KB |
Output is correct |
11 |
Correct |
528 ms |
67064 KB |
Output is correct |
12 |
Correct |
2943 ms |
102640 KB |
Output is correct |
13 |
Execution timed out |
4018 ms |
117636 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |