제출 #603525

#제출 시각아이디문제언어결과실행 시간메모리
603525SeDunionSplit the Attractions (IOI19_split)C++17
0 / 100
8 ms9940 KiB
#include "split.h" #include<algorithm> #include<iostream> #include<vector> #include<assert.h> using namespace std; const int N = 2e5 + 123; vector<int>g[N]; int used[N]; int n, a, b, c; vector<int>vec, ans; int av = -1, bv = -1; int tin[N], tout[N], timer, sz[N]; void dfs(int v) { used[v] = 1; sz[v] = 1; tin[v] = timer++; tout[v] = timer++; for (int to : g[v]) if (!used[to]) { dfs(to); sz[v] += sz[to]; if (sz[to] >= a && n - sz[to] >= b) { av = to, bv = v; } } } bool cmp(int a, int b) { return tin[a] < tin[b]; } bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } vector<int> find_split(int n_, int a_, int b_, int c_, vector<int> p, vector<int> q) { n = n_, a = a_, b = b_, c = c_; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); // a <= b <= c // a <= n/3 ? // b <= n/2 ? int m = p.size(); for (int i = 0 ; i < m ; ++ i) { g[p[i]].emplace_back(q[i]); g[q[i]].emplace_back(p[i]); } int root = 0; for (int i = 0 ; i < n ; ++ i) { if ((int)g[i].size() == 1) root = i; } ans = vector<int>(n, 3); dfs(root); if (av == -1) return vector<int>(n, 0); vector<int>vec; for (int i = 0 ; i < n ; ++ i) { vec.emplace_back(i); } for (int i = 0 ; i < n ; ++ i) cout << tin[i] << " "; cout << " t\n"; sort(vec.begin(), vec.end(), cmp); for (int v : vec) cout << v << " "; cout << " ve\n"; for (int v : vec) { if (a && upper(av, v)) ans[v] = 1, a--; if (b && !upper(av, v)) ans[v] = 2, b--; } assert(a == 0 && b == 0); return ans; }
#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...