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;
int N;
int c[100000],par[100000],t[100000];
bool vis[100000];
vector<int>e[100000],ee[100000];
mt19937 E(869120);
vector<int>res;
void dfs2(int x){
vis[x]=true;
for(int i:ee[x]){
if(!vis[i]){
e[x].push_back(i);
e[i].push_back(x);
dfs2(i);
}
}
}
void make_tree(){
for(int i=0;i<N;i++){
vis[i]=false;
random_shuffle(ee[i].begin(),ee[i].end());
}
dfs2(E()%N);
}
void dfs(int x,int from){
par[x]=from;
c[x]=1;
for(int i:e[x]){
if(i==from)continue;
dfs(i,x);
c[x]+=c[i];
}
}
vector<int>find_split(int n,int aaa,int bbb,int ccc,vector<int>p,vector<int>q){
N=n;
pair<int,int>P[3];
P[0]={aaa,1};
P[1]={bbb,2};
P[2]={ccc,3};
sort(P,P+3);
int m=p.size();
for(int i=0;i<m;i++){
ee[p[i]].push_back(q[i]);
ee[q[i]].push_back(p[i]);
}
for(int _=0;_<10000;_++){
res=vector<int>(n,0);
for(int i=0;i<n;i++){
e[i].clear();
t[i]=i;
}
make_tree();
dfs(0,0);
pair<int,int>mn={0xE869120,-1};
for(int i=0;i<n;i++){
if(c[i]>=P[0].first){
mn=min(mn,{c[i],i});
}
if(n-c[i]>=P[0].first){
mn=min(mn,{n-c[i],-i});
}
}
if(mn.second==0){
continue;
}
else if(mn.second>0){
queue<int>que;
que.push(mn.second);
res[par[mn.second]]=0xE869120;
while(P[0].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[0].second;
P[0].first--;
for(int i:e[x]){
que.push(i);
}
}
}
res[par[mn.second]]=0;
while(!que.empty())que.pop();
que.push(par[mn.second]);
while(!que.empty()&&P[1].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[1].second;
P[1].first--;
for(int i:e[x]){
que.push(i);
}
}
}
if(!P[1].first){
for(int i=0;i<n;i++){
if(!res[i])res[i]=P[2].second;
}
break;
}
else{
continue;
}
}
else{
queue<int>que;
que.push(par[-mn.second]);
res[-mn.second]=0xE869120;
while(P[0].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[0].second;
P[0].first--;
for(int i:e[x]){
que.push(i);
}
}
}
res[-mn.second]=0;
while(!que.empty())que.pop();
que.push(-mn.second);
while(!que.empty()&&P[1].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[1].second;
P[1].first--;
for(int i:e[x]){
que.push(i);
}
}
}
if(!P[1].first){
for(int i=0;i<n;i++){
if(!res[i])res[i]=P[2].second;
}
break;
}
else{
continue;
}
}
}
return res;
}
# | 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... |