// 14.47
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1000111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int n, cnt;
int deg[maxn], dep[maxn];
bool edge[maxn], found;
vector<int> cycles;
vector<pii> adj[maxn];
void Init(int N) {
n = N;
for(int i = 0; i < maxn; i++){
deg[i] = 0;
adj[i].clear();
}
}
void Link(int A, int B){
deg[A]++;
deg[B]++;
adj[A].pb(mp(B, ++cnt));
adj[B].pb(mp(A, cnt));
// cout << "ok link" << endl;
}
void DFS(int x, int p){
if(found)
return;
for(pii v : adj[x]){
if(found || v.fi == p || edge[v.se])
continue;
if(dep[v.fi]){
cycles.pb(dep[x] - dep[v.fi] + 1);
found = 1;
}
if(!dep[v.fi]){
dep[v.fi] = dep[x] + 1;
DFS(v.fi, x);
}
}
}
void checkCycles(){
cycles.clear();
memset(dep, 0, sizeof(dep));
for(int i = 0; i < n; i++){
if(cycles.size() >= 2)
return;
if(!dep[i]){
found = 0;
dep[i] = 1;
DFS(i, -1);
}
}
}
bool check(int x){
for(pii v : adj[x]){
edge[v.se] = 1;
deg[v.fi]--;
}
bool ret = 1;
for(int i = 0; i < n; i++){
if(i != x && deg[i] > 2){
ret = 0;
break;
}
}
if(ret)
checkCycles();
ret &= (cycles.size() == 0);
for(pii v : adj[x]){
edge[v.se] = 0;
deg[v.fi]++;
}
return ret;
}
int CountCritical(){
// cout << "ok count" << endl;
int sz[5], v[5];
memset(sz, 0, sizeof(sz));
int max_degree = 0;
for(int i = 0; i < n; i++){
int cur = min(deg[i], 4);
max_degree = max(max_degree, cur);
v[cur] = i;
sz[cur]++;
}
if(max_degree <= 1)
return n;
if(max_degree == 2){
checkCycles();
if(cycles.size() > 1)
return 0;
if(cycles.size() == 1)
return cycles[0];
return n;
}
if(max_degree == 3){
int ans = check(v[3]);
for(pii x : adj[v[3]])
ans += check(x.fi);
return ans;
}
if(max_degree == 4){
if(sz[4] > 1)
return 0;
int ans = check(v[4]);
return ans;
}
}
Compilation message
rings.cpp: In function 'int CountCritical()':
rings.cpp:150:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
31608 KB |
Output is correct |
2 |
Correct |
33 ms |
31888 KB |
Output is correct |
3 |
Correct |
33 ms |
31904 KB |
Output is correct |
4 |
Correct |
32 ms |
31904 KB |
Output is correct |
5 |
Correct |
38 ms |
31976 KB |
Output is correct |
6 |
Correct |
40 ms |
32264 KB |
Output is correct |
7 |
Correct |
28 ms |
32264 KB |
Output is correct |
8 |
Correct |
42 ms |
32264 KB |
Output is correct |
9 |
Correct |
35 ms |
32264 KB |
Output is correct |
10 |
Correct |
34 ms |
32264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
529 ms |
48272 KB |
Output is correct |
2 |
Correct |
1014 ms |
57556 KB |
Output is correct |
3 |
Correct |
932 ms |
61252 KB |
Output is correct |
4 |
Correct |
1350 ms |
63988 KB |
Output is correct |
5 |
Correct |
1367 ms |
65208 KB |
Output is correct |
6 |
Correct |
1396 ms |
108080 KB |
Output is correct |
7 |
Correct |
921 ms |
108080 KB |
Output is correct |
8 |
Correct |
1511 ms |
108080 KB |
Output is correct |
9 |
Correct |
1340 ms |
108080 KB |
Output is correct |
10 |
Correct |
750 ms |
108080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
31608 KB |
Output is correct |
2 |
Correct |
33 ms |
31888 KB |
Output is correct |
3 |
Correct |
33 ms |
31904 KB |
Output is correct |
4 |
Correct |
32 ms |
31904 KB |
Output is correct |
5 |
Correct |
38 ms |
31976 KB |
Output is correct |
6 |
Correct |
40 ms |
32264 KB |
Output is correct |
7 |
Correct |
28 ms |
32264 KB |
Output is correct |
8 |
Correct |
42 ms |
32264 KB |
Output is correct |
9 |
Correct |
35 ms |
32264 KB |
Output is correct |
10 |
Correct |
34 ms |
32264 KB |
Output is correct |
11 |
Correct |
77 ms |
108080 KB |
Output is correct |
12 |
Correct |
95 ms |
108080 KB |
Output is correct |
13 |
Correct |
135 ms |
108080 KB |
Output is correct |
14 |
Correct |
70 ms |
108080 KB |
Output is correct |
15 |
Correct |
90 ms |
108080 KB |
Output is correct |
16 |
Correct |
85 ms |
108080 KB |
Output is correct |
17 |
Correct |
42 ms |
108080 KB |
Output is correct |
18 |
Correct |
48 ms |
108080 KB |
Output is correct |
19 |
Correct |
88 ms |
108080 KB |
Output is correct |
20 |
Correct |
98 ms |
108080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
31608 KB |
Output is correct |
2 |
Correct |
33 ms |
31888 KB |
Output is correct |
3 |
Correct |
33 ms |
31904 KB |
Output is correct |
4 |
Correct |
32 ms |
31904 KB |
Output is correct |
5 |
Correct |
38 ms |
31976 KB |
Output is correct |
6 |
Correct |
40 ms |
32264 KB |
Output is correct |
7 |
Correct |
28 ms |
32264 KB |
Output is correct |
8 |
Correct |
42 ms |
32264 KB |
Output is correct |
9 |
Correct |
35 ms |
32264 KB |
Output is correct |
10 |
Correct |
34 ms |
32264 KB |
Output is correct |
11 |
Correct |
77 ms |
108080 KB |
Output is correct |
12 |
Correct |
95 ms |
108080 KB |
Output is correct |
13 |
Correct |
135 ms |
108080 KB |
Output is correct |
14 |
Correct |
70 ms |
108080 KB |
Output is correct |
15 |
Correct |
90 ms |
108080 KB |
Output is correct |
16 |
Correct |
85 ms |
108080 KB |
Output is correct |
17 |
Correct |
42 ms |
108080 KB |
Output is correct |
18 |
Correct |
48 ms |
108080 KB |
Output is correct |
19 |
Correct |
88 ms |
108080 KB |
Output is correct |
20 |
Correct |
98 ms |
108080 KB |
Output is correct |
21 |
Execution timed out |
4027 ms |
108080 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
31608 KB |
Output is correct |
2 |
Correct |
33 ms |
31888 KB |
Output is correct |
3 |
Correct |
33 ms |
31904 KB |
Output is correct |
4 |
Correct |
32 ms |
31904 KB |
Output is correct |
5 |
Correct |
38 ms |
31976 KB |
Output is correct |
6 |
Correct |
40 ms |
32264 KB |
Output is correct |
7 |
Correct |
28 ms |
32264 KB |
Output is correct |
8 |
Correct |
42 ms |
32264 KB |
Output is correct |
9 |
Correct |
35 ms |
32264 KB |
Output is correct |
10 |
Correct |
34 ms |
32264 KB |
Output is correct |
11 |
Correct |
529 ms |
48272 KB |
Output is correct |
12 |
Correct |
1014 ms |
57556 KB |
Output is correct |
13 |
Correct |
932 ms |
61252 KB |
Output is correct |
14 |
Correct |
1350 ms |
63988 KB |
Output is correct |
15 |
Correct |
1367 ms |
65208 KB |
Output is correct |
16 |
Correct |
1396 ms |
108080 KB |
Output is correct |
17 |
Correct |
921 ms |
108080 KB |
Output is correct |
18 |
Correct |
1511 ms |
108080 KB |
Output is correct |
19 |
Correct |
1340 ms |
108080 KB |
Output is correct |
20 |
Correct |
750 ms |
108080 KB |
Output is correct |
21 |
Correct |
77 ms |
108080 KB |
Output is correct |
22 |
Correct |
95 ms |
108080 KB |
Output is correct |
23 |
Correct |
135 ms |
108080 KB |
Output is correct |
24 |
Correct |
70 ms |
108080 KB |
Output is correct |
25 |
Correct |
90 ms |
108080 KB |
Output is correct |
26 |
Correct |
85 ms |
108080 KB |
Output is correct |
27 |
Correct |
42 ms |
108080 KB |
Output is correct |
28 |
Correct |
48 ms |
108080 KB |
Output is correct |
29 |
Correct |
88 ms |
108080 KB |
Output is correct |
30 |
Correct |
98 ms |
108080 KB |
Output is correct |
31 |
Execution timed out |
4027 ms |
108080 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |