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 "split.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
using namespace std;
const int N=1e6+99;
int n,m,p=-1,X,Y,Time,st[N],ft[N],sz[N],vis[N],cnt[N];
vector<int> res,g[N];
void dfs(int u){
//eror(u);
vis[u]=sz[u]=1;
st[u]=Time++;
for(auto v : g[u]){
if(vis[v]) continue ;
dfs(v);
sz[u]+=sz[v];
}
if(sz[u]>=X && n-sz[u]>=Y){
p=u;
}
if(sz[u]>=Y && n-sz[u]>=X){
p=u;
}
ft[u]=Time;
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> P, vector<int> Q) {
n=_n; m=P.size(); res.resize(n);
vector<pair<int,int>> Z;
Z.pb({a,1}),Z.pb({b,2}),Z.pb({c,3});
sort(all(Z));
X=Z[0].F,Y=Z[1].F;
f(i,0,m){
//cout<<P[i]<<" "<<Q[i]<<endl;
g[P[i]].pb(Q[i]),g[Q[i]].pb(P[i]);
}
dfs(0);
if(p==-1){
return res;
}
if(sz[p]<X || n-sz[p]<Y){
swap(X,Y);
swap(Z[0],Z[1]);
}
int cnt0=0,cnt1=0,cnt2=0;
f(i,0,n){
int u=st[i];
if(st[p]<=u && u<ft[p]){
cnt2++;
if(u<st[p]+X){
cnt0++;
res[i]=1;
}
}
else{
if(u>=st[p]) u-=cnt[p];
if(u<Y){
cnt1++;
res[i]=2;
}
}
}
if(cnt2!=sz[p]){
assert(0);
}
if(cnt0!=X){
//assert(0);
}
f(i,0,n){
if(res[i]==0){
res[i]=Z[2].S;
}
else if(res[i]==1){
res[i]=Z[0].S;
}
else if(res[i]==2){
res[i]=Z[1].S;
}
a-=(res[i]==1);
b-=(res[i]==2);
c-=(res[i]==3);
}
if(a>0 || b>0 || c>0){
//assert(0);
}
return res;
}
/*
6 5
2 2 2
0 2
1 2
2 3
3 4
3 5
*/
# | 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... |