Submission #418484

#TimeUsernameProblemLanguageResultExecution timeMemory
418484AdOjis485Split the Attractions (IOI19_split)C++14
0 / 100
99 ms12356 KiB
#include "split.h" #include <iostream> #include <algorithm> using namespace std; vector<vector<int> > adi; vector<int> res; pair<int, int> ans = {-1, -1}; int dfs(int v, int p, int a, int b, int c) { int count = 1; for(int next : adi[v]) { if(next == p) continue; count += dfs(next, v, a, b, c); } if(count >= a && a + b + c - count >= b) ans = {v, p}; return count; } void set_ans(int v, int p, int val, int& num) { //cerr << v << " " << p << " " << val << " " << num << '\n'; if(num == 0) return; res[v] = val; num --; for(int next : adi[v]) { if(next == p) continue; set_ans(next, v, val, num); } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { res.resize(n); adi.resize(n); int m = p.size(); for(int i = 0; i < m; i ++) { adi[p[i]].push_back(q[i]); adi[q[i]].push_back(p[i]); } vector<pair<int, int> > vals = {{a, 1}, {b, 2}, {c, 3}}; sort(vals.begin(), vals.end()); if(a == 1) { int num = b; set_ans(0, -1, 2, num); bool afound = false; int cnt2 = 0; for(int i = 0; i < n; i ++) { if(res[i] == 0) { if(afound) res[i] = 3; else { afound = true; res[i] = 1; } } else cnt2 ++; } while(cnt2 < b){} } else if(m == n - 1) { dfs(0, -1, vals[0].first, vals[1].first, vals[2].first); if(ans.first >= 0) { //cerr << ans.first << " " << ans.second << '\n'; int num = vals[0].first; set_ans(ans.first, ans.second, vals[0].second, num); num = vals[1].first; set_ans(ans.second, ans.first, vals[1].second, num); for(int i = 0; i < n; i ++) { if(res[i] == 0) res[i] = vals[2].second; } } } return res; }
#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...