#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;
map<int,int> ok;
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()) {
ok.clear();
if(deg[4].size()<=1) {
for(auto u : deg[4]) if(check(u)) ok[u];
}
return ok.size();
}
if(deg[3].size()) {
ok.clear();
for(auto u : deg[3]) {
if(check(u)) ok[u];
for(auto v : way[u]) if(check(v)) ok[v];
}
return ok.size();
}
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
29 ms |
31960 KB |
Output is correct |
3 |
Correct |
31 ms |
31960 KB |
Output is correct |
4 |
Correct |
27 ms |
31960 KB |
Output is correct |
5 |
Correct |
25 ms |
31960 KB |
Output is correct |
6 |
Correct |
27 ms |
31960 KB |
Output is correct |
7 |
Correct |
33 ms |
31960 KB |
Output is correct |
8 |
Correct |
27 ms |
31960 KB |
Output is correct |
9 |
Correct |
33 ms |
32196 KB |
Output is correct |
10 |
Correct |
33 ms |
32196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
520 ms |
46592 KB |
Output is correct |
2 |
Correct |
987 ms |
60608 KB |
Output is correct |
3 |
Correct |
883 ms |
60608 KB |
Output is correct |
4 |
Correct |
1358 ms |
64064 KB |
Output is correct |
5 |
Correct |
1281 ms |
64704 KB |
Output is correct |
6 |
Correct |
1282 ms |
94668 KB |
Output is correct |
7 |
Correct |
865 ms |
94668 KB |
Output is correct |
8 |
Correct |
1993 ms |
94668 KB |
Output is correct |
9 |
Correct |
1517 ms |
94668 KB |
Output is correct |
10 |
Correct |
960 ms |
94668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
29 ms |
31960 KB |
Output is correct |
3 |
Correct |
31 ms |
31960 KB |
Output is correct |
4 |
Correct |
27 ms |
31960 KB |
Output is correct |
5 |
Correct |
25 ms |
31960 KB |
Output is correct |
6 |
Correct |
27 ms |
31960 KB |
Output is correct |
7 |
Correct |
33 ms |
31960 KB |
Output is correct |
8 |
Correct |
27 ms |
31960 KB |
Output is correct |
9 |
Correct |
33 ms |
32196 KB |
Output is correct |
10 |
Correct |
33 ms |
32196 KB |
Output is correct |
11 |
Correct |
156 ms |
94668 KB |
Output is correct |
12 |
Correct |
109 ms |
94668 KB |
Output is correct |
13 |
Correct |
177 ms |
94668 KB |
Output is correct |
14 |
Correct |
92 ms |
94668 KB |
Output is correct |
15 |
Correct |
112 ms |
94668 KB |
Output is correct |
16 |
Correct |
85 ms |
94668 KB |
Output is correct |
17 |
Execution timed out |
4077 ms |
94668 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
29 ms |
31960 KB |
Output is correct |
3 |
Correct |
31 ms |
31960 KB |
Output is correct |
4 |
Correct |
27 ms |
31960 KB |
Output is correct |
5 |
Correct |
25 ms |
31960 KB |
Output is correct |
6 |
Correct |
27 ms |
31960 KB |
Output is correct |
7 |
Correct |
33 ms |
31960 KB |
Output is correct |
8 |
Correct |
27 ms |
31960 KB |
Output is correct |
9 |
Correct |
33 ms |
32196 KB |
Output is correct |
10 |
Correct |
33 ms |
32196 KB |
Output is correct |
11 |
Correct |
156 ms |
94668 KB |
Output is correct |
12 |
Correct |
109 ms |
94668 KB |
Output is correct |
13 |
Correct |
177 ms |
94668 KB |
Output is correct |
14 |
Correct |
92 ms |
94668 KB |
Output is correct |
15 |
Correct |
112 ms |
94668 KB |
Output is correct |
16 |
Correct |
85 ms |
94668 KB |
Output is correct |
17 |
Execution timed out |
4077 ms |
94668 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
27768 KB |
Output is correct |
2 |
Correct |
29 ms |
31960 KB |
Output is correct |
3 |
Correct |
31 ms |
31960 KB |
Output is correct |
4 |
Correct |
27 ms |
31960 KB |
Output is correct |
5 |
Correct |
25 ms |
31960 KB |
Output is correct |
6 |
Correct |
27 ms |
31960 KB |
Output is correct |
7 |
Correct |
33 ms |
31960 KB |
Output is correct |
8 |
Correct |
27 ms |
31960 KB |
Output is correct |
9 |
Correct |
33 ms |
32196 KB |
Output is correct |
10 |
Correct |
33 ms |
32196 KB |
Output is correct |
11 |
Correct |
520 ms |
46592 KB |
Output is correct |
12 |
Correct |
987 ms |
60608 KB |
Output is correct |
13 |
Correct |
883 ms |
60608 KB |
Output is correct |
14 |
Correct |
1358 ms |
64064 KB |
Output is correct |
15 |
Correct |
1281 ms |
64704 KB |
Output is correct |
16 |
Correct |
1282 ms |
94668 KB |
Output is correct |
17 |
Correct |
865 ms |
94668 KB |
Output is correct |
18 |
Correct |
1993 ms |
94668 KB |
Output is correct |
19 |
Correct |
1517 ms |
94668 KB |
Output is correct |
20 |
Correct |
960 ms |
94668 KB |
Output is correct |
21 |
Correct |
156 ms |
94668 KB |
Output is correct |
22 |
Correct |
109 ms |
94668 KB |
Output is correct |
23 |
Correct |
177 ms |
94668 KB |
Output is correct |
24 |
Correct |
92 ms |
94668 KB |
Output is correct |
25 |
Correct |
112 ms |
94668 KB |
Output is correct |
26 |
Correct |
85 ms |
94668 KB |
Output is correct |
27 |
Execution timed out |
4077 ms |
94668 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |