# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
280333 | stoyan_malinin | Split the Attractions (IOI19_split) | C++14 | 6 ms | 5248 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 "split.h"
//#include "grader.cpp"
#include <iostream>
#include <functional>
using namespace std;
const int MAXN = 1e5 + 5;
int n;
vector <int> graph[MAXN];
vector <vector <int>> solve1(int a, int b, int c)
{
vector <int> order;
vector <bool> used;
used.assign(n+5, false);
function <void(int)> dfs = [&](int x)
{
order.push_back(x);
//cout << x << " ";
used[x] = true;
for(int y: graph[x])
{
if(used[y]==false) dfs(y);
}
};
//cout << '\n';
dfs(0);
vector <vector <int>> out;
out.push_back({});
for(int i = 0;i<a;i++) out.back().push_back(order[i]);
out.push_back({});
for(int i = a;i<a+b;i++) out.back().push_back(order[i]);
out.push_back({});
for(int i = a+b;i<a+b+c;i++) out.back().push_back(order[i]);
return out;
}
int recogniseSubtask()
{
int maxDeg = 0;
for(int x = 0;x<n;x++)
{
maxDeg = max(maxDeg, int(graph[x].size()));
}
if(maxDeg<=2) return 1;
}
vector <int> getOutput(vector <vector <int>> v, int a, int b, int c)
{
if(v[1].size()==a) swap(v[0], v[1]);
if(v[2].size()==a) swap(v[0], v[2]);
if(v[2].size()==b) swap(v[1], v[2]);
vector <int> out;
out.resize(a+b+c);
for(int x: v[0]) out[x] = 1;
for(int x: v[1]) out[x] = 2;
for(int x: v[2]) out[x] = 3;
return out;
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q)
{
n = _n;
for(int i = 0;i<n;i++)
{
graph[ p[i] ].push_back(q[i]);
graph[ q[i] ].push_back(p[i]);
}
int subtask = recogniseSubtask();
vector <vector <int>> rawOutput;
if(subtask==1)
{
rawOutput = solve1(c, b, a);
return getOutput(rawOutput, a, b, c);
}
}
/*
5 5
1 2 2
0 1
1 2
2 3
3 4
4 0
*/
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... |