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 sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
const int maxn=1e5+5;
#define ll long long
vector<int> v[maxn];
bool vis[maxn];
vector<int> top;
void dfs(int u){
top.pb(u);
vis[u]=1;
for(int x:v[u]){
if(!vis[x]) dfs(x);
}
}
int sz[maxn],par[maxn];
void dfs(int u,int p){
sz[u]=1;
par[u]=p;
for(int x:v[u]){
if(x==p) continue;
dfs(x,u);
sz[u]+=sz[x];
}
}
vector<int> val;
bool cmp(int a,int b){
return val[a-1]<val[b-1];
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
vector<int> ans(n,0);
REP(i,sz(p)){
v[p[i]].pb(q[i]),v[q[i]].pb(p[i]);
}
val={a,b,c};
vector<int> asd={1,2,3};
sort(ALL(asd),cmp);
sort(ALL(val));
if(sz(p)==n-1){
dfs(0,-1);
int mn=0;
REP(i,n){
if(sz[i]>=val[0] and sz[i]<sz[mn]) mn=i;
}
if(mn==0){
return ans;
}
vis[par[mn]]=1;
dfs(mn);
REP(i,val[0]) ans[top[i]]=asd[0];
top.clear();
vis[par[mn]]=0;
dfs(par[mn]);
REP(i,val[1]) ans[top[i]]=asd[1];
REP(i,n) if(!ans[i]) ans[i]=asd[2];
}
else{
dfs(0);
REP(i,a) ans[top[i]]=1;
REP(i,b) ans[top[i+a]]=2;
REP(i,c) ans[top[i+a+b]]=3;
}
return ans;
}
# | 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... |