This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 100001
vector<int> color;
vector<int> e[N];
int s[N];
int A[N];
int B[N];
int C[N];
int x,y,z;
void dfs(int v,int u,int a,int b,int c){
s[v]=1;
for(auto& i:e[v]){
if(i==u) continue;
dfs(i,v,a,b,c);
s[v]+=s[i];
if(A[i]) A[v]=1;
if(B[i]) B[v]=1;
if(C[i]) C[v]=1;
}
if(s[v]==a) A[v]=1;
if(s[v]==b) B[v]=1;
if(s[v]==c) C[v]=1;
}
void Color(int v,int u,int a,int b,int c){
if(!z){
if(A[v] && s[v]==a+b) z=3;
if(B[v] && s[v]==a+b) z=3;
if(A[v] && s[v]==a+c) z=2;
if(C[v] && s[v]==a+c) z=2;
if(B[v] && s[v]==c+b) z=1;
if(C[v] && s[v]==c+b) z=1;
if(z) color[v]=4;
}
if(color[v]==4 && s[v]==a && z!=1 && !y){
color[v]=1;
y=5-z;
}
if(color[v]==4 && s[v]==b && z!=2 && !y){
color[v]=2;
y=4-z;
}
if(color[v]==4 && s[v]==c && z!=3 && !y){
color[v]=3;
y=3-z;
}
for(auto& i:e[v]){
if(i==u) continue;
color[i]=color[v];
Color(i,v,a,b,c);
}
}
vector<int> find_split(int n,int a,int b,int c,vector<int> p,vector<int> q){
for(int i=x=y=z=0;i<n-1;i++){
e[p[i]].append(q[i]);
e[q[i]].append(p[i]);
}
vector<int> v;
for(int i=0;i<n;i++){
if(e[i].size()==1)
v.append(i);
color.append(0);
}
while(!z && x<20){
dfs(v[x],-1,a,b,c);
Color(v[x],-1,a,b,c);
x++;
}
for(int i=0;i<n;i++){
if(color[i]==0) color[i]=z;
if(color[i]==4) color[i]=y;
}
return color;
}
# | 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... |