#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n;
vector<int> way[maxn];
vector<int> deg[10];
int cut[maxn];
int sz, cy, vis[maxn];
stack<int> st;
int ok[maxn];
void Init(int _n) {
n = _n;
}
void cycle(int u, int last, int ban) {
if(vis[u]) {
while(!st.empty()) {
int v = st.top(); st.pop();
sz++;
if(v==u) break;
}
cy++;
return ;
}
vis[u] = 1; st.push(u);
for(auto v : way[u]) {
if(v!=ban && v!=last && vis[v]<2) {
cycle(v,u,ban);
}
}
vis[u] = 2;
if(!st.empty()) st.pop();
}
int check(int u) {
memset(cut,0,sizeof(cut));
for(auto v : way[u]) cut[v]++;
for(int i=1;i<=n;i++) if(i!=u && way[i].size()-cut[i]>2) return 0;
sz = cy = 0; memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++) if(i!=u && !vis[i]) cycle(i,0,u);
return cy==0;
}
int CountCritical() {
for(int i=0;i<=4;i++) deg[i].clear();
for(int x=1;x<=n;x++) deg[min(4,(int)way[x].size())].push_back(x);
if(deg[4].size()) {
memset(ok,0,sizeof(ok));
if(deg[4].size()<=1) {
for(auto u : deg[4]) if(!ok[u] && check(u)) ok[u] = 1;
}
int res = 0;
for(int x=1;x<=n;x++) res += ok[x];
return res;
}
if(deg[3].size()) {
memset(ok,0,sizeof(ok));
int u = deg[3][0];
if(!ok[u] && check(u)) ok[u] = 1;
for(auto v : way[u]) if(!ok[v] && check(v)) ok[v] = 1;
int res = 0;
for(int x=1;x<=n;x++) res += ok[x];
return res;
}
sz = cy = 0; memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++) if(!vis[i]) cycle(i,0,0);
if(cy==0) return n;
else if(cy==1) return sz;
else return 0;
}
void Link(int x, int y) {
x++; y++;
way[x].push_back(y); way[y].push_back(x);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
32 ms |
35916 KB |
Output is correct |
3 |
Correct |
35 ms |
35916 KB |
Output is correct |
4 |
Correct |
26 ms |
35916 KB |
Output is correct |
5 |
Correct |
27 ms |
35916 KB |
Output is correct |
6 |
Correct |
28 ms |
35916 KB |
Output is correct |
7 |
Correct |
29 ms |
35916 KB |
Output is correct |
8 |
Correct |
27 ms |
35916 KB |
Output is correct |
9 |
Correct |
34 ms |
35984 KB |
Output is correct |
10 |
Correct |
34 ms |
35988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
46600 KB |
Output is correct |
2 |
Correct |
961 ms |
64444 KB |
Output is correct |
3 |
Correct |
926 ms |
64444 KB |
Output is correct |
4 |
Correct |
1215 ms |
64444 KB |
Output is correct |
5 |
Correct |
1273 ms |
64616 KB |
Output is correct |
6 |
Correct |
1238 ms |
94816 KB |
Output is correct |
7 |
Correct |
831 ms |
94816 KB |
Output is correct |
8 |
Correct |
1407 ms |
94816 KB |
Output is correct |
9 |
Correct |
1282 ms |
94816 KB |
Output is correct |
10 |
Correct |
971 ms |
94816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
32 ms |
35916 KB |
Output is correct |
3 |
Correct |
35 ms |
35916 KB |
Output is correct |
4 |
Correct |
26 ms |
35916 KB |
Output is correct |
5 |
Correct |
27 ms |
35916 KB |
Output is correct |
6 |
Correct |
28 ms |
35916 KB |
Output is correct |
7 |
Correct |
29 ms |
35916 KB |
Output is correct |
8 |
Correct |
27 ms |
35916 KB |
Output is correct |
9 |
Correct |
34 ms |
35984 KB |
Output is correct |
10 |
Correct |
34 ms |
35988 KB |
Output is correct |
11 |
Correct |
105 ms |
94816 KB |
Output is correct |
12 |
Correct |
106 ms |
94816 KB |
Output is correct |
13 |
Correct |
193 ms |
94816 KB |
Output is correct |
14 |
Correct |
113 ms |
94816 KB |
Output is correct |
15 |
Correct |
139 ms |
94816 KB |
Output is correct |
16 |
Correct |
86 ms |
94816 KB |
Output is correct |
17 |
Correct |
149 ms |
94816 KB |
Output is correct |
18 |
Correct |
79 ms |
94816 KB |
Output is correct |
19 |
Correct |
87 ms |
94816 KB |
Output is correct |
20 |
Correct |
151 ms |
94816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
32 ms |
35916 KB |
Output is correct |
3 |
Correct |
35 ms |
35916 KB |
Output is correct |
4 |
Correct |
26 ms |
35916 KB |
Output is correct |
5 |
Correct |
27 ms |
35916 KB |
Output is correct |
6 |
Correct |
28 ms |
35916 KB |
Output is correct |
7 |
Correct |
29 ms |
35916 KB |
Output is correct |
8 |
Correct |
27 ms |
35916 KB |
Output is correct |
9 |
Correct |
34 ms |
35984 KB |
Output is correct |
10 |
Correct |
34 ms |
35988 KB |
Output is correct |
11 |
Correct |
105 ms |
94816 KB |
Output is correct |
12 |
Correct |
106 ms |
94816 KB |
Output is correct |
13 |
Correct |
193 ms |
94816 KB |
Output is correct |
14 |
Correct |
113 ms |
94816 KB |
Output is correct |
15 |
Correct |
139 ms |
94816 KB |
Output is correct |
16 |
Correct |
86 ms |
94816 KB |
Output is correct |
17 |
Correct |
149 ms |
94816 KB |
Output is correct |
18 |
Correct |
79 ms |
94816 KB |
Output is correct |
19 |
Correct |
87 ms |
94816 KB |
Output is correct |
20 |
Correct |
151 ms |
94816 KB |
Output is correct |
21 |
Execution timed out |
4038 ms |
94816 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
32 ms |
35916 KB |
Output is correct |
3 |
Correct |
35 ms |
35916 KB |
Output is correct |
4 |
Correct |
26 ms |
35916 KB |
Output is correct |
5 |
Correct |
27 ms |
35916 KB |
Output is correct |
6 |
Correct |
28 ms |
35916 KB |
Output is correct |
7 |
Correct |
29 ms |
35916 KB |
Output is correct |
8 |
Correct |
27 ms |
35916 KB |
Output is correct |
9 |
Correct |
34 ms |
35984 KB |
Output is correct |
10 |
Correct |
34 ms |
35988 KB |
Output is correct |
11 |
Correct |
506 ms |
46600 KB |
Output is correct |
12 |
Correct |
961 ms |
64444 KB |
Output is correct |
13 |
Correct |
926 ms |
64444 KB |
Output is correct |
14 |
Correct |
1215 ms |
64444 KB |
Output is correct |
15 |
Correct |
1273 ms |
64616 KB |
Output is correct |
16 |
Correct |
1238 ms |
94816 KB |
Output is correct |
17 |
Correct |
831 ms |
94816 KB |
Output is correct |
18 |
Correct |
1407 ms |
94816 KB |
Output is correct |
19 |
Correct |
1282 ms |
94816 KB |
Output is correct |
20 |
Correct |
971 ms |
94816 KB |
Output is correct |
21 |
Correct |
105 ms |
94816 KB |
Output is correct |
22 |
Correct |
106 ms |
94816 KB |
Output is correct |
23 |
Correct |
193 ms |
94816 KB |
Output is correct |
24 |
Correct |
113 ms |
94816 KB |
Output is correct |
25 |
Correct |
139 ms |
94816 KB |
Output is correct |
26 |
Correct |
86 ms |
94816 KB |
Output is correct |
27 |
Correct |
149 ms |
94816 KB |
Output is correct |
28 |
Correct |
79 ms |
94816 KB |
Output is correct |
29 |
Correct |
87 ms |
94816 KB |
Output is correct |
30 |
Correct |
151 ms |
94816 KB |
Output is correct |
31 |
Execution timed out |
4038 ms |
94816 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |