제출 #156545

#제출 시각아이디문제언어결과실행 시간메모리
156545MoNsTeR_CuBeSplit the Attractions (IOI19_split)C++17
0 / 100
893 ms1048580 KiB
#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[0].second, 1); coloring(last, node, v[1].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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...