#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 1000010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int N;
unordered_set <int> st[maxn];
int d[maxn],sz[maxn],edges[maxn];
int maxD;
int E = 0;
int p[maxn];
vi adj[maxn];
unordered_set <int> cycles;
int ncomp;
int fl(int x){
if (p[x] == x) return x;
return p[x] = fl(p[x]);
}
int pr[5][maxn];
int edgesr[5][maxn], szr[5][maxn];
vpi all_edges;
unordered_set <int> cyclesr[maxn];
vi pos;
int flr(int i, int x){
if (pr[i][x] == x) return x;
return pr[i][x] = flr(i, pr[i][x]);
}
void add(int A, int B){
edges[fl(B)]++;
if (fl(A) != fl(B)){
int pA = fl(A), pB = fl(B);
sz[pB] += sz[pA];
edges[pB] += edges[pA];
if (cycles.find(pA) != cycles.end()) cycles.erase(pA);
p[pA] = pB;
}
if (edges[fl(B)] >= sz[fl(B)]) cycles.insert(fl(B));
}
void addr(int i, int A, int B){
edgesr[i][flr(i,B)]++;
if (flr(i, A) != flr(i,B)){
int pA = flr(i,A), pB = flr(i,B);
szr[i][pB] += szr[i][pA];
edgesr[i][pB] += edgesr[i][pA];
if (cyclesr[i].find(pA) != cyclesr[i].end()) cyclesr[i].erase(pA);
pr[i][pA] = pB;
}
if (edgesr[i][flr(i,B)] >= szr[i][flr(i,B)]) cyclesr[i].insert(flr(i,B));
}
int bigx;
void Init(int N_) {
N = N_;
ncomp = N;
maxD = 0;
FOR(i,0,N-1) p[i] = i, sz[i] = 1;
FOR(i,0,4) FOR(j,0,N-1) pr[i][j] = j,szr[i][j] = 1;
bigx = -1;
}
int deg1[maxn];
void Link(int A, int B) {
st[d[A]].erase(A); st[d[B]].erase(B);
d[A]++; d[B]++;
st[d[A]].insert(A); st[d[B]].insert(B);
adj[A].pb(B); adj[B].pb(A);
if (pos.empty() && (d[A] == 3 || d[B] == 3)){
if (d[A] == 3){
aFOR(i, adj[A]) pos.pb(i);
pos.pb(A);
}else if (d[B] == 3){
pos.pb(B); aFOR(i, adj[B]) pos.pb(i);
}
FOR(i,0,pos.size()-1){
aFOR(j, all_edges) if (j.f != pos[i] && j.s != pos[i]) addr(i,j.f,j.s);
}
}
if (bigx == -1 && (d[A] >= 4 || d[B] >= 4)){
if (d[A] >= 4) bigx = A;
else if (d[B] >= 4) bigx = B;
aFOR(i, all_edges) if (i.f != bigx && i.s != bigx) addr(4,i.f,i.s);
}
all_edges.pb(pi(A,B));
maxD = max({maxD, d[A], d[B]});
E++;
add(A,B);
FOR(i,0,pos.size()-1) if (A != pos[i] && B != pos[i]) addr(i,A,B);
}
int CountCritical() {
if (maxD >= 4){
if (st[4].size() == 1){
int x = *st[4].begin();
bool no = 0;
if (!cyclesr[4].empty()) no = 1;
aFOR(i, st[3]) if (find(all(adj[x]), i) == adj[x].end()) no = 1;
if (no) return 0;
return 1;
}
else return 0;
}else if (maxD <= 1) return N;
else if (maxD == 3){
if (st[3].size() > 4) return 0;
int ans = 0;
//cout << pos[0] << ' ';
/*
FOR(i,0,N-1) cout << flr(1,i) << ' ';
cout << '\n';
FOR(i,0,N-1) cout << szr[1][flr(1,i)] << ' ';
cout << '\n';
FOR(i,0,N-1) cout << edgesr[1][flr(1,i)] << ' ';
cout << '\n';
cout << cyclesr[1].size() << ' ';
cout << '\n';
*/
aFOR(i, pos){
bool no = 0;
aFOR(j, st[3]) if (i != j && find(all(adj[i]), j) == adj[i].end()) no = 1;
if (no) continue;
if (cyclesr[i].empty()) ans++;
}
return ans;
}else{
if (cycles.size() == 0) return N;
else if (cycles.size() == 1) return sz[fl(*cycles.begin())];
else return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
133428 KB |
Output is correct |
2 |
Correct |
71 ms |
134224 KB |
Output is correct |
3 |
Incorrect |
83 ms |
134372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
780 ms |
204264 KB |
Output is correct |
2 |
Runtime error |
2234 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
133428 KB |
Output is correct |
2 |
Correct |
71 ms |
134224 KB |
Output is correct |
3 |
Incorrect |
83 ms |
134372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
133428 KB |
Output is correct |
2 |
Correct |
71 ms |
134224 KB |
Output is correct |
3 |
Incorrect |
83 ms |
134372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
133428 KB |
Output is correct |
2 |
Correct |
71 ms |
134224 KB |
Output is correct |
3 |
Incorrect |
83 ms |
134372 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |