Submission #603685

#TimeUsernameProblemLanguageResultExecution timeMemory
603685SeDunionSplit the Attractions (IOI19_split)C++17
100 / 100
116 ms31216 KiB
#include "split.h" #include<algorithm> #include<iostream> #include<vector> #include<assert.h> using namespace std; const int N = 2e5 + 123; vector<int>g[N], tg[N]; int used[N]; int n, a, b, c; vector<int>ans; int V = -1; int tin[N], tout[N], timer, sz[N], fup[N], par[N]; void dfs(int v) { used[v] = 1; sz[v] = 1; tin[v] = fup[v] = timer++; for (int to : g[v]) { if (!used[to]) { tg[v].emplace_back(to); par[to] = v; dfs(to); sz[v] += sz[to]; fup[v] = min(fup[v], fup[to]); } else { fup[v] = min(fup[v], tin[to]); } } if (sz[v] >= a && V == -1) V = v; tout[v] = timer++; } bool cmp(int a, int b) { return tin[a] < tin[b]; } bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int gg[4]; void tree(int v, int c, int &d) { if (!d || ans[v] != 3) return; --d; ans[v] = c; for (int to : tg[v]) tree(to, c, d); } void eert(int v, int c, int &d) { if (!d || ans[v] != 3) return; --d; ans[v] = c; for (int to : g[v]) eert(to, c, d); } vector<int> find_split(int n_, int a_, int b_, int c_, vector<int> p, vector<int> q) { n = n_, a = a_, b = b_, c = c_; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); if (a_ == a && b_ == b && c_ == c) gg[1] = 1, gg[2] = 2, gg[3] = 3; if (a_ == a && b_ == c && c_ == b) gg[1] = 1, gg[3] = 2, gg[2] = 3; if (a_ == b && b_ == a && c_ == c) gg[2] = 1, gg[1] = 2, gg[3] = 3; if (a_ == b && b_ == c && c_ == a) gg[2] = 1, gg[3] = 2, gg[1] = 3; if (a_ == c && b_ == a && c_ == b) gg[3] = 1, gg[1] = 2, gg[2] = 3; if (a_ == c && b_ == b && c_ == a) gg[3] = 1, gg[2] = 2, gg[1] = 3; // a <= b <= c // a <= n/3 ? // b <= n/2 ? int m = p.size(); for (int i = 0 ; i < m ; ++ i) { g[p[i]].emplace_back(q[i]); g[q[i]].emplace_back(p[i]); } ans = vector<int>(n, 3); par[0] = -1; dfs(0); if (V == -1) return vector<int>(n, 0); int v = V; if (sz[v] + b <= n) { tree(v, 1, a); eert(par[v], 2, b); } else { ans[v] = 2; b--; for (int to : tg[v]) if (fup[to] > tin[v]) tree(to, 2, b); for (int to : tg[v]) if (fup[to] <= tin[v]) tree(to, 2, b); if (par[V] != -1) eert(par[v], 1, a); if (a) return vector<int>(n, 0); } for (int &i : ans) i = gg[i]; 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...