This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;++i)
#define pool(i, a, b) for(ll i=a-1;i>=b;--i)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 500100
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007
int n, mm=0, cent=-1, ans;
vc<vc<int>> edg;
vc<int> cnt;
void Init(int N){
int n=N;
ans=n;
edg.resize(n);
cnt.resize(n+1, 0);cnt[0]=n;
loop(i, 0, n) cnt.ps(i);
}
void add(int a, int b){
--cnt[edg[a].size()];
--cnt[edg[b].size()];
edg[a].ps(b);
edg[b].ps(a);
++cnt[edg[a].size()];
++cnt[edg[b].size()];
}
void Link(int a, int b){
if(edg[a].size()<edg[b].size()) swap(a, b);
if(ans==0) return;
if(edg[a].size()>=3 and edg[b].size()>=3)ans=0;
else if(edg[a].size()>=3){
if(cent==a) add(a, b);
else if(cent==-1){
cent=a;
add(a, b);
int kok3za=0;
fore(v, edg[a]) if(edg[v].size()==3) ++kok3za;
ans=(kok3za==cnt[3]);
}
else ans=0;
}
else if(edg[a].size()==2){
add(a, b);
if(cnt[3]<=4){
ll br=0;
loop(i, 0, n){
ll kok3=(edg[i].size()==3);
fore(v, edg[i]) if(edg[v].size()==3) ++kok3;
br+=(kok3==cnt[3]);
}
ans=br;
}
else ans=0;
}
else add(a, b);
}
int CountCritical(){return ans;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |