이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}else if(subGraph[node] >= v[1].first && N-subGraph[node] >= v[0].first){
coloring(node, last, v[1].second, 1);
coloring(last, node, v[0].second, 0);
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... |