Submission #204383

#TimeUsernameProblemLanguageResultExecution timeMemory
204383ADJASplit the Attractions (IOI19_split)C++14
29 / 100
603 ms1048580 KiB
#include "split.h" #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <set> #include <map> #include <algorithm> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <string> #define sz(x) (int) x.size() #define all(x) x.begin(), x.end() using namespace std; const int MAXN = 105000; int n, a, b, c; vector <pair<int, int>> p; vector<int> g[MAXN]; vector<int> res; int sz[MAXN]; int par[MAXN]; int deg[MAXN]; bool used[MAXN]; void dfs(int v, int p = -1) { sz[v] = 1; par[v] = p; for (int to : g[v]) { if (to == p) { continue; } dfs(to, v); sz[v] += sz[to]; } } void paint(int v, int bad, int color, int& need) { // cerr << v << " " << color << " " << need << endl; if (v == bad || need == 0) { return; } res[v] = color; need--; for (int to : g[v]) { if (to == par[v]) { continue; } paint(to, bad, color, need); } } void doPaint(int v, int num) { used[v] = true; if (num <= a) { res[v] = 1; } else if (num <= a + b) { res[v] = 2; } else { res[v] = 3; } for (int to : g[v]) { if (used[to]) { continue; } doPaint(to, num + 1); } } void solveOne() { int st = 0; for (int i = 0; i < n; i++) { if (deg[i] == 1) { st = i; } } doPaint(st, 1); } vector<int> find_split(int N, int A, int B, int C, vector<int> FROM, vector<int> TO) { n = N; a = A; b = B; c = C; p = {{a, 1}, {b, 2}, {c, 3}}; res.assign(n, 0); sort(all(p)); for (int i = 0; i < sz(FROM); i++) { int from = FROM[i], to = TO[i]; g[from].push_back(to); g[to].push_back(from); deg[from]++; deg[to]++; } int mxDeg = deg[0]; for (int i = 0; i < n; i++) { mxDeg = max(mxDeg, deg[i]); } if (mxDeg == 2) { solveOne(); return res; } dfs(0); /* for (int i = 0; i < n; i++) { cerr << sz[i] << " "; } cerr << endl; */ do { for (int i = 0; i < n; i++) { // cerr << sz[i] << " " << n - sz[i] << " " << p[0].first << " " << p[1].first << endl; if (sz[i] >= p[0].first && n - sz[i] >= p[1].first) { res.assign(n, p[2].second); paint(0, i, p[1].second, p[1].first); paint(i, -1, p[0].second, p[0].first); return res; } } } while (next_permutation(all(p))); 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...