#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const long long INF = 1e9;
const int TMX = 1 << 18;
const long long llINF = 1e18;
const long long mod = 1e9+7;
const long long hashmod = 100003;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;
int n,Q,fl,ind[1000005];
int ans,mx,c[1000005],c2[1000005];
int cnt[1000005],par[1000005];
int p[1000005];
vec v[1000005];
int Find(int x) {return (x^p[x] ? p[x] = Find(p[x]) : x);}
void Ind3(int x) {
mx++;
ans = 0;
if(++cnt[x] == mx) ans++;
for(int i : v[x]) {
if(++cnt[i] == mx) ans++;
}
}
void Ind4(int x) {
mx++;
ans = 0;
if(++cnt[x] == mx) ans++;
}
bool merge(int x,int y) {
x = Find(x), y = Find(y);
if(x == y) return false;
p[y] = x; return true;
}
vec g;
bool canCycle;
void Cycle(int x,int pr) {
if(c2[x]) {
canCycle = 1;
if(++cnt[x] == mx) ans++;
for(int i = par[x];i^x;i = par[i]) {
if(++cnt[i] == mx) ans++;
}
return;
}
if(c[x]) {g.pb(x); return;}
c[x] = c2[x] = 1;
g.pb(x);
for(int i : v[x]) if(i != pr) par[x] = i, Cycle(i,x);
c2[x] = 0;
}
void update(int x,int y) {
v[x].pb(y), v[y].pb(x);
ind[x]++, ind[y]++;
if(ind[x] == 3) Ind3(x);
if(ind[y] == 3) Ind3(y);
if(ind[x] == 4) Ind4(x);
if(ind[y] == 4) Ind4(y);
if(!merge(x,y)) {
g.clear();
canCycle = 0;
if(c[x]) swap(x,y);
mx++; ans = 0;
Cycle(x,-1);
if(!canCycle) {
//if(g.size() > 2) exit(-1);
//if(g.size() < 2) return;
for(int i : g) if(++cnt[i] == mx) ans++;
}
}
}
void Init(int n_) {
ans = n = n_;
for(int i = 1;i <= n;i++) p[i] = i;
}
void Link(int A,int B) {
update(A+1,B+1);
}
int CountCritical() {
return ans;
}
Compilation message
rings.cpp:6: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
6 | #pragma gcc optimize("O3")
|
rings.cpp:7: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
7 | #pragma gcc optimize("Ofast")
|
rings.cpp:8: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
8 | #pragma gcc optimize("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23684 KB |
Output is correct |
2 |
Correct |
15 ms |
24056 KB |
Output is correct |
3 |
Correct |
15 ms |
24020 KB |
Output is correct |
4 |
Correct |
17 ms |
23892 KB |
Output is correct |
5 |
Correct |
16 ms |
24204 KB |
Output is correct |
6 |
Correct |
14 ms |
24404 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
24128 KB |
Output is correct |
9 |
Correct |
14 ms |
24060 KB |
Output is correct |
10 |
Correct |
15 ms |
24104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
44236 KB |
Output is correct |
2 |
Correct |
748 ms |
65812 KB |
Output is correct |
3 |
Correct |
1194 ms |
87304 KB |
Output is correct |
4 |
Correct |
959 ms |
82604 KB |
Output is correct |
5 |
Correct |
1033 ms |
93420 KB |
Output is correct |
6 |
Correct |
1147 ms |
122880 KB |
Output is correct |
7 |
Correct |
1139 ms |
86396 KB |
Output is correct |
8 |
Correct |
887 ms |
73008 KB |
Output is correct |
9 |
Correct |
1006 ms |
76328 KB |
Output is correct |
10 |
Correct |
978 ms |
94928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23684 KB |
Output is correct |
2 |
Correct |
15 ms |
24056 KB |
Output is correct |
3 |
Correct |
15 ms |
24020 KB |
Output is correct |
4 |
Correct |
17 ms |
23892 KB |
Output is correct |
5 |
Correct |
16 ms |
24204 KB |
Output is correct |
6 |
Correct |
14 ms |
24404 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
24128 KB |
Output is correct |
9 |
Correct |
14 ms |
24060 KB |
Output is correct |
10 |
Correct |
15 ms |
24104 KB |
Output is correct |
11 |
Incorrect |
15 ms |
24148 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23684 KB |
Output is correct |
2 |
Correct |
15 ms |
24056 KB |
Output is correct |
3 |
Correct |
15 ms |
24020 KB |
Output is correct |
4 |
Correct |
17 ms |
23892 KB |
Output is correct |
5 |
Correct |
16 ms |
24204 KB |
Output is correct |
6 |
Correct |
14 ms |
24404 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
24128 KB |
Output is correct |
9 |
Correct |
14 ms |
24060 KB |
Output is correct |
10 |
Correct |
15 ms |
24104 KB |
Output is correct |
11 |
Incorrect |
15 ms |
24148 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23684 KB |
Output is correct |
2 |
Correct |
15 ms |
24056 KB |
Output is correct |
3 |
Correct |
15 ms |
24020 KB |
Output is correct |
4 |
Correct |
17 ms |
23892 KB |
Output is correct |
5 |
Correct |
16 ms |
24204 KB |
Output is correct |
6 |
Correct |
14 ms |
24404 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
24128 KB |
Output is correct |
9 |
Correct |
14 ms |
24060 KB |
Output is correct |
10 |
Correct |
15 ms |
24104 KB |
Output is correct |
11 |
Correct |
390 ms |
44236 KB |
Output is correct |
12 |
Correct |
748 ms |
65812 KB |
Output is correct |
13 |
Correct |
1194 ms |
87304 KB |
Output is correct |
14 |
Correct |
959 ms |
82604 KB |
Output is correct |
15 |
Correct |
1033 ms |
93420 KB |
Output is correct |
16 |
Correct |
1147 ms |
122880 KB |
Output is correct |
17 |
Correct |
1139 ms |
86396 KB |
Output is correct |
18 |
Correct |
887 ms |
73008 KB |
Output is correct |
19 |
Correct |
1006 ms |
76328 KB |
Output is correct |
20 |
Correct |
978 ms |
94928 KB |
Output is correct |
21 |
Incorrect |
15 ms |
24148 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |