제출 #1283845

#제출 시각아이디문제언어결과실행 시간메모리
1283845duckindogSplit the Attractions (IOI19_split)C++20
0 / 100
2 ms344 KiB
#include <bits/stdc++.h> #include "split.h" using namespace std; const int N = 100'000 + 10; int n, a, b, c; vector<int> ad[N]; vector<int> ret; int k; void doColor(int u, int p, int color) { if (k <= 0) return; k -= 1; ret[u] = color; for (const auto& v : ad[u]) { if (v == p) continue; doColor(v, u, color); } } int sz[N]; bool doneColor = false; void dfs(int u, int p = -1) { if (doneColor) return; sz[u] = 1; for (const auto& v : ad[u]) { if (v == p) continue; dfs(v, u); sz[u] += sz[v]; if (doneColor) return; } if (sz[u] >= a && n - sz[u] >= a) { if (sz[u] >= b) { doneColor = true; k = b; doColor(u, p, 2); k = a; doColor(p, u, 3); } else if (n - sz[u] >= b) { doneColor = true; k = b; doColor(p, u, 2); k = a; doColor(u, p, 3); } } } vector<int> find_split(int _n, int _a, int _b, int _c, vector<int> _p, vector<int> _q) { { // input n = _n; a = _a; b = _b; c = _c; for (int i = 0; i < (int)_p.size(); ++i) { int u = _p[i], v = _q[i]; ad[u].push_back(v); ad[v].push_back(u); } if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); } assert((int)_p.size() == n - 1); ret.resize(n, 1); dfs(0); if (!doneColor) { ret.assign(n, 0); } else { int cntA = 0, cntB = 0, cntC = 0; for (const auto& x : ret) { (x == 1 ? cntC : x == 2 ? cntB : cntA) += 1; } if (cntA != a || cntB != b || cntC != c) { cerr << "Wrong\n"; for (;;); // ret.assign(n, 0); } } return ret; }
#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...