# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226331 | AaronNaidu | Split the Attractions (IOI19_split) | C++14 | 8 ms | 2816 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] = 1;
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] = 2;
for (auto i : graph[node])
{
if (i != parent[node] and toRet[node] == 3)
{
if(num1 > a) {
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(3);
}
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);
return toRet;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |