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>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
using namespace std;
vi res;
vector<vi>G;
vector<pair<int,int> >v;
bool ok=false;
vi peso;
int n;
void dfs1(int nodo, int p){//esto es para flutfitear el mas bajito
if(v[0].F==0)return;
res[nodo]=v[0].S;
v[0].F--;
for(auto it : G[nodo]){
if(it==p)continue;
dfs1(it,nodo);
}
}
void dfs2(int nodo, int p){
if(v[1].F==0)return;
res[nodo]=v[1].S;
v[1].F--;
for(auto it : G[nodo]){
if(it==p)continue;
dfs2(it,nodo);
}
}
void check(int nodo, int p){
for(auto it : G[nodo]){
if(it==p)continue;
check(it,nodo);
peso[nodo]+=peso[it];
if(peso[it]>=v[0].F && n-v[0].F>=v[1].F && ok==0){
ok=1;
dfs1(it,nodo);
dfs2(nodo,it);
}
if(peso[it]>=v[1].F && n-v[1].F>=v[0].F && ok==0){
ok=1;
dfs1(nodo,it);
dfs2(it,nodo);
}
}
peso[nodo]++;
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
int m=p.size();
n=N;
G.assign(n,vi());
peso.resize(n+1,0);
for(int i=0;i<m;i++){
G[p[i]].pb(q[i]);
G[q[i]].pb(p[i]);
}
v.pb({a,1});v.pb({b,2});v.pb({c,3});
sort(v.begin(),v.end());
res.assign(n,v[2].S);
check(0,-1);
if(!ok)res.assign(n,0);
return res;
}
/*
10 9
6 2 2
0 1
0 2
0 3
3 4
4 8
8 9
4 7
3 5
3 6
*/
# | 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... |