Submission #645122

#TimeUsernameProblemLanguageResultExecution timeMemory
645122dattranxxxSplit the Attractions (IOI19_split)C++17
Compilation error
0 ms0 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; vector<int> adj[N]; int n, m; vector<int> result; int R = -1, R2 = 0, t = 0; pair<int, int> _x[3], x[3]; int low[N], in[N], siz[N]; vector<int> tri[N]; void build(int u) { in[u] = low[u] = ++t; int flag = 1; siz[u] = 1; for (int v : adj[u]) if (in[v]) low[u] = min(low[u], in[v]); else tri[u].emplace_back(v), build(v), low[u] = min(low[u], low[v]), siz[u] += siz[v], flag &= siz[v] < x[0].first; flag &= siz[u] >= x[0].first; if (flag) tot.emplace_back(u); } int res[N], ans[N]; void dfs(int u, int c) { ans[u] = c; for (int v : tri[u]) dfs(v, c); } int fixx(int u) { res[u] = x[0].second; x[0].first--; if (x[0].first == 0) return 1; for (int v : tri[u]) if (ans[v] == x[0].second) { if (fixx(v)) return 1; } return 0; } int fixy(int u) { res[u] = x[1].second; x[1].first--; if (x[1].first == 0) return 1; for (int v : tri[u]) if (ans[v] == x[2].second) { if (fixy(v)) return 1; } return 0; } vector<int> print() { for (int v = 0; v < n; ++v) res[v] = x[2].second; fixx(R); fixy(R2); for (int v = 0; v < n; ++v) result.emplace_back(res[v]); return result; } vector<int> impossible() { result.clear(); for (int v = 0; v < n; ++v) result.emplace_back(0); return result; } int P1, P2; void dfs2(int u) { for (int v : tri[u]) if (low[v] < in[R]) { if (P1 - siz[v] >= x[0].first) P1 -= siz[v], dfs(v, x[2].second); else dfs2(v); } } vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q) { n = _n, m = p.size(); x[0] = {a, 1}, x[1] = {b, 2}, x[2] = {c, 3}; sort(x, x + 3); for (int i = 0; i < 3; ++i) _x[i] = x[i]; for (int i = 0, u, v; i < m; ++i) u = p[i], v = q[i], adj[u].emplace_back(v), adj[v].emplace_back(u); build(0); for (int _ : tot) { for (int i = 0; i < 3; ++i) x[i] = _x[i]; R = _, R2 = 0; for (int v = 0; v < n; ++v) ans[v] = x[2].second; dfs(R, x[0].second); int P1 = siz[R], P2 = n - P1; dfs2(R); if (P2 < P1) { swap(R, R2); swap(P1, P2); for (int v = 0; v < n; ++v) if (ans[v] == x[0].second) ans[v] = x[2].second; else ans[v] = x[0].second; } vector<int> result = print(); if (x[0].first || x[1].first) continue; return result; } return impossible; }

Compilation message (stderr)

split.cpp: In function 'void build(int)':
split.cpp:20:13: error: 'tot' was not declared in this scope
   20 |   if (flag) tot.emplace_back(u);
      |             ^~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:75:16: error: 'tot' was not declared in this scope
   75 |   for (int _ : tot) {
      |                ^~~
split.cpp:93:10: error: could not convert 'impossible' from 'std::vector<int>()' to 'std::vector<int>'
   93 |   return impossible;
      |          ^~~~~~~~~~
      |          |
      |          std::vector<int>()