Submission #152591

#TimeUsernameProblemLanguageResultExecution timeMemory
152591MylderoSplit the Attractions (IOI19_split)C++14
0 / 100
4 ms2680 KiB
#include "split.h" #include <algorithm> #include <queue> using namespace std; typedef vector<int> vi; typedef pair<int, int> ii; int n, m; ii att[3]; vi nb[100005]; int size[100005]; int parent[100005]; bool visited[100005]; bool visited2[100005]; int bestA = 111111, bestAV = -1; int bestB = 111111, bestBV = -1; vi res; void bfs_fill1 (int s) { queue<int> q; q.push(s); for (int count = 0; count < att[0].first; count++) { int v = q.front(); q.pop(); res[v] = att[0].second; for (int w : nb[v]) { if (w != parent[v]) { q.push(w); } } } } void bfs_fill2 (int s) { queue<int> q; q.push(s); for (int count = 0; count <= att[1].first; count++) { int v = q.front(); q.pop(); res[v] = att[1].second; for (int w : nb[v]) { if (!visited2[w]) { q.push(w); visited2[w] = true; } } } } void dfs (int v, int p) { visited[v] = true; parent[v] = p; size[v] = 1; for (int w : nb[v]) { if (!visited[w]) { dfs(w, v); size[v] += size[w]; } } if (size[v] >= att[0].first && size[v] < bestA) { bestA = size[v]; bestAV = v; } if (size[v] >= att[1].first && size[v] < bestB) { bestB = size[v]; bestBV = v; } } void solve () { dfs(0, -1); if (n - bestA >= att[1].first) { visited2[bestAV] = true; bfs_fill1(bestAV); bfs_fill2(parent[bestAV]); } else if (n - bestB >= att[0].first) { swap(att[0], att[1]); visited2[bestBV] = true; bfs_fill1(bestBV); bfs_fill2(parent[bestBV]); } else { return; } for (int i = 0; i < n; i++) { if (res[i] == 0) { res[i] = att[2].second; } } } vi find_split(int N, int a, int b, int c, vi p, vi q) { n = N; m = p.size(); att[0] = make_pair(a, 1); att[1] = make_pair(b, 2); att[2] = make_pair(c, 3); sort(att, att+3); for (int i = 0; i < m; i++) { nb[p[i]].push_back(q[i]); nb[q[i]].push_back(p[i]); } res = vi(n); solve(); 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...