Submission #1077371

#TimeUsernameProblemLanguageResultExecution timeMemory
1077371IgnutSplit the Attractions (IOI19_split)C++17
0 / 100
556 ms1048576 KiB
// Ignut #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 123; int n; int a, b, c; int colorA, colorB, colorC; vector<int> g[MAXN]; int sz[MAXN]; int parent[MAXN]; int flag = -1; int vert = -1; int dfs0(int v, int par) { sz[v] = 1; parent[v] = par; for (int to : g[v]) if (to != par) sz[v] += dfs0(to, v); return sz[v]; } vector<int> res; void dfs(int v, int par, int col, int lim) { res[v] = col; lim --; if (lim == 0) return; for (int to : g[v]) { if (to == par || to == vert) continue; dfs(to, v, col, lim); if (lim == 0) return; } } vector<int> find_split(int N, int A, int B, int C, vector<int> P, vector<int> Q) { vector<pair<int, int>> col = {{A, 1}, {B, 2}, {C, 3}}; sort(col.begin(), col.end()); A = col[0].first, colorA = col[0].first; B = col[1].first, colorB = col[1].first; C = col[2].first, colorC = col[2].first; int M = P.size(); for (int i = 0; i < M; i ++) { g[P[i]].push_back(Q[i]); g[Q[i]].push_back(P[i]); } dfs0(0, -1); for (int i = 0; i < N; i ++) { if (sz[i] >= A && N - sz[i] >= B) { vert = i; flag = 1; break; } if (sz[i] >= B && N - sz[i] >= B) { vert = i; flag = 2; break; } } res.assign(N, 0); if (vert == -1) return res; for (int i = 0; i < N; i ++) res[i] = colorC; if (flag == 1) { dfs(0, -1, colorB, B); dfs(vert, parent[vert], colorA, A); } else { dfs(0, -1, colorA, A); dfs(vert, parent[vert], colorB, B); } 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...