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;
vector< vector< int > > Graph;
vector< pair<int, int> > v(3);
vector< int > subGraph;
vector< int > ans;
void coloring(int node, int parent, int color, int index){
if(v[index].first){
v[index].first--;
ans[node] = color;
}else{
ans[node] = v[2].second;
}
for(int a : Graph[node]){
if(a == parent) continue;
coloring(a, node, color, index);
}
}
bool dfs(int node, int last){
int N = Graph.size();
subGraph[node] = 1;
//cout << "VISITING " << node << endl;
for(int a : Graph[node]){
if(a == last) continue;
if(dfs(a, node)){
return true;
}
subGraph[node] += subGraph[a];
}
//cout << "NODE " << node << ' ' << "LAST " << last << " SUBGRAPH " << subGraph[node] << endl;
if(subGraph[node] >= v[0].first && N-subGraph[node] >= v[1].first){
coloring(node, last, v[0].second, 0);
coloring(last, node, v[1].second, 1);
return true;
}
return false;
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
Graph.resize(N);
ans.resize(N);
subGraph.resize(N);
for(int i = 0; i < (int) p.size(); i++){
Graph[p[i]].push_back(q[i]);
Graph[q[i]].push_back(p[i]);
}
v[0] = {a, 1};
v[1] = {b, 2};
v[2] = {c, 3};
sort(v.begin(), v.end());
dfs(0,-1);
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... |