Submission #204372

#TimeUsernameProblemLanguageResultExecution timeMemory
204372ADJASplit the Attractions (IOI19_split)C++14
22 / 100
937 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; void dfs(int v, const vector<vector<int>>& g, vector<int>& sz, vector <int>& par, int p = -1) { sz[v] = 1; par[v] = p; for (int to : g[v]) { if (to == p) { continue; } dfs(to, g, sz, par, v); sz[v] += sz[to]; } } void paint(int v, int bad, int color, int& need, vector<vector<int>>& g, vector<int>& res, vector <int>& par) { // 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, g, res, par); } } 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; vector <pair<int, int>> p; vector<vector<int>> g; vector<int> res; vector <int> sz, par; p = {{a, 1}, {b, 2}, {c, 3}}; g.assign(n + 10, vector<int>()); sz.assign(n + 10, 0); par.assign(n + 10, 0); 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); } dfs(0, g, sz, par); /* for (int i = 0; i < n; i++) { cerr << sz[i] << " "; } cerr << endl; */ res.assign(n, 0); sort(all(p)); 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, g, res, par); paint(i, -1, p[0].second, p[0].first, g, res, par); 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...