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 ll long long
#define vi vector<int>
#define pb push_back
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
const int MX = 200005;
vi g[MX],adj[MX];
int par[MX],dep[MX],sz[MX];
pii A[MX];
bitset<MX> vis;
vi ans;
void dfs(int u,int p,int d = 0){
par[u] = p;
vis[u] = 1;
dep[u] = d;
sz[u] = 1;
for(auto v:g[u]){
if(vis[v]) continue;
adj[u].pb(v);
adj[v].pb(u);
dfs(v,u,d-1);
sz[u] += sz[v];
}
}
void assign(int u,int val){
vis[u] = 1;
if(A[val].F){
ans[u] = A[val].S;
A[val].F--;
}
else ans[u] = A[2].S;
for(auto v:adj[u]){
if(!vis[v]) assign(v,val);
}
}
vi find_split(int n, int a, int b, int c, vi p, vi q) {
A[0] = {a,1};
A[1] = {b,2};
A[2] = {c,3};
sort(A,A+3);
ans.resize(n);
REP(i,(int)p.size()){
g[p[i]].pb(q[i]);
g[q[i]].pb(p[i]);
}
int mxd = 0;
int root = 0;
REP(i,n){
mxd = max(mxd,(int)g[i].size());
if(g[i].size() == 1) root = i;
}
dfs(root,root);
if(mxd == 2){
int cur = root,cnt = 0;
while(1){
if(cnt < a) ans[cur] = 1;
else if(cnt < a+b) ans[cur] = 2;
else ans[cur] = 3;
cnt++;
if(adj[cur].size()) cur = adj[cur][0];
else break;
}
return ans;
}
if(a == 1){
vector<pii> v;
REP(i,n) v.pb({dep[i],i});
sort(v.begin(),v.end());
REP(i,n){
if(i == 0) ans[v[i].S] = 1;
else if(i <= b) ans[v[i].S] = 2;
else ans[v[i].S] = 3;
}
return ans;
}
vis.reset();
REP(i,n){
if(sz[i] >= A[0].F and n-sz[i] >= A[0].F){
vis[i] = 1;
assign(par[i],0);
assign(i,1);
return ans;
}
}
return vi(n,0);
}
# | 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... |