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;
}
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]);
}
f(i,0,n){
int u=st[i];
if(st[p]<=u && u<ft[p]){
if(u<st[p]+X){
res[i]=1;
}
}
else{
if(u>=st[p]) u-=cnt[p];
if(u<Y){
res[i]=2;
}
}
}
f(i,0,n){
if(res[i]==0){
res[i]=Z[2].S;
}
if(res[i]==1){
res[i]=Z[0].S;
}
if(res[i]==2){
res[i]=Z[1].S;
}
}
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... |