Submission #723179

#TimeUsernameProblemLanguageResultExecution timeMemory
723179GrandTiger1729Split the Attractions (IOI19_split)C++17
29 / 100
104 ms15960 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q){ int m = p.size(); vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++){ int u = p[i], v = q[i]; g[u].push_back(v); g[v].push_back(u); } vector<int> sz(n), pa(n); { vector<bool> vis(n); function<void(int)> dfs = [&](int u){ vis[u] = 1; sz[u] = 1; for (auto &v: g[u]){ if (vis[v]) continue; dfs(v); sz[u] += sz[v]; pa[v] = u; } }; dfs(0); } auto get = [&](int x) -> int { if (x == 1) return a; if (x == 2) return b; if (x == 3) return c; return -1; }; function<vector<int>(int, int, int, int)> draw = [&](int aa, int bb, int cc, int u) -> vector<int> { vector<bool> vis(n); vector<int> ret(n); function<void(int, int, int &)> dfs = [&](int u, int x, int &cnt){ vis[u] = 1; if (cnt > 0){ ret[u] = x; cnt--; } for (auto &v: g[u]){ if (vis[v]) continue; dfs(v, x, cnt); } }; vis[pa[u]] = 1; dfs(u, aa, *(new int(get(aa)))); vis[pa[u]] = 0; dfs(0, bb, *(new int(get(bb)))); for (int j = 0; j < n; j++) if (ret[j] == 0) ret[j] = cc; return ret; }; for (int i = 0; i < n; i++){ if (sz[i] >= a && n - sz[i] >= b) return draw(1, 2, 3, i); if (sz[i] >= b && n - sz[i] >= a) return draw(2, 1, 3, i); if (sz[i] >= b && n - sz[i] >= c) return draw(2, 3, 1, i); if (sz[i] >= c && n - sz[i] >= b) return draw(3, 2, 1, i); if (sz[i] >= c && n - sz[i] >= a) return draw(3, 1, 2, i); if (sz[i] >= a && n - sz[i] >= c) return draw(1, 3, 2, i); } return vector<int>(n, 0); }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:6:6: warning: unused variable 'm' [-Wunused-variable]
    6 |  int m = p.size();
      |      ^
#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...