# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226335 | 2020-04-23T11:54:37 Z | AaronNaidu | Split the Attractions (IOI19_split) | C++14 | 7 ms | 2688 KB |
#include <bits/stdc++.h> using namespace std; vector<int> graph[100001]; int n, a, b, c, num; bool visited[100001]; vector<int> toRet; int parent[100001]; int subSize[100001]; int num1 = 0; int num2 = 0; int dfs(int node, int par) { visited[node] = true; parent[node] = par; int subsize = 1; for (auto i : graph[node]) { if (!visited[i]) { subsize += dfs(i, node); } } subSize[node] = subsize; return subsize; } void dfs1(int node) { num1++; if (num1 > a) { return; } toRet[node] = 10; for (auto i : graph[node]) { if (i != parent[node]) { if(num1 > a) { return; } dfs1(i); } } } void dfs2(int node) { num2++; if (num2 > b) { return; } toRet[node] = 20; for (auto i : graph[node]) { if (i != parent[node] and toRet[node] == 3) { if(num2 > b) { return; } dfs2(i); } } } vector<int> find_split(int ln, int la, int lb, int lc, vector<int> p, vector<int> q) { n = ln; a = la; b = lb; c = lc; vector<int> v = {a, b, c}; sort(v.begin(), v.end()); a = v[0]; b = v[1]; c = v[2]; for (int i = 0; i < p.size(); i++) { graph[p[i]].push_back(q[i]); graph[q[i]].push_back(p[i]); } for (int i = 0; i < n; i++) { toRet.push_back(30); } num = 0; dfs(0, -1); int best = n+1; int bestVertex = -1; for (int i = 0; i < n; i++) { if (subSize[i] >= a) { if (best > subSize[i]) { best = subSize[i]; bestVertex = i; } } } //cout << "Best is " << best << " at vertex " << bestVertex << "\n"; if (n - best < b) { for (int i = 0; i < n; i++) { toRet[i] = 0; } return toRet; } dfs1(bestVertex); dfs2(0); if (a >= b and b >= c) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 3; } else if (toRet[i] == 20) { toRet[i] = 2; } else { toRet[i] = 1; } } } else if (a >= c and c >= b) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 2; } else if (toRet[i] == 20) { toRet[i] = 3; } else { toRet[i] = 1; } } } else if (b >= a and a >= c) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 3; } else if (toRet[i] == 20) { toRet[i] = 1; } else { toRet[i] = 2; } } } else if (b >= c and c >= a) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 1; } else if (toRet[i] == 20) { toRet[i] = 3; } else { toRet[i] = 2; } } } else if (c >= a and a >= b) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 2; } else if (toRet[i] == 20) { toRet[i] = 1; } else { toRet[i] = 3; } } } else if (c >= b and b >= a) { for (int i = 0; i < n; i++) { if (toRet[i] == 10) { toRet[i] = 1; } else if (toRet[i] == 20) { toRet[i] = 2; } else { toRet[i] = 3; } } } return toRet; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | ok, correct split |
2 | Correct | 6 ms | 2688 KB | ok, correct split |
3 | Correct | 6 ms | 2688 KB | ok, correct split |
4 | Incorrect | 6 ms | 2688 KB | invalid split: #1=1, #2=1, #3=2 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | ok, correct split |
2 | Correct | 7 ms | 2688 KB | ok, correct split |
3 | Incorrect | 6 ms | 2688 KB | invalid split: #1=1, #2=3, #3=1 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | invalid split: #1=1, #2=3, #3=1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | invalid split: #1=2, #2=1, #3=6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | ok, correct split |
2 | Correct | 6 ms | 2688 KB | ok, correct split |
3 | Correct | 6 ms | 2688 KB | ok, correct split |
4 | Incorrect | 6 ms | 2688 KB | invalid split: #1=1, #2=1, #3=2 |
5 | Halted | 0 ms | 0 KB | - |