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 <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 3e2;
vector<int> perm = {0, 1, 2};
void sort(int &a, int &b, int &c){
vector<int> v = {a, b, c};
do {
a = v[perm[0]], b = v[perm[1]], c = v[perm[2]];
if (a <= b && b <= c) break;
} while (next_permutation(perm.begin(), perm.end()));
}
vector<int> orig(vector<int> v){
if (v[0] == 0) return v;
vector<int> res = v;
for (int i = 0; i < v.size(); i++){
res[i] = perm[v[i] - 1] + 1;
}
return res;
}
vector<int> g[MAXN];
int cnt[MAXN];
bool used[MAXN];
int par[MAXN];
vector<int> ord;
void dfs(int v, int p){
used[v] = true;
ord.push_back(v);
par[v] = p;
cnt[v] = 1;
for (int u : g[v]){
if (!used[u]){
dfs(u, v);
cnt[v] += cnt[u];
}
}
}
vector<int> ord2;
void dfs2(int v, int p, int x){
ord2.push_back(v);
for (int u : g[v]){
if (u != p && u != x) dfs2(u, v, x);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
vector<int> res(n, 0);
sort(a, b, c);
int m = p.size();
for (int i = 0; i < m; i++){
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
bool sub2 = true;
for (int i = 0; i < n; i++){
if (g[i].size() > 2) sub2 = false;
}
if (a == 1 || sub2) {
int ind = 0;
for (int i = 0; i < n; i++) {
if (g[i].size() < g[ind].size()) ind = i;
}
dfs(ind, ind);
for (int i = 0; i < n; i++) {
if (i < a) res[ord[i]] = 1;
else if (i < a + b) res[ord[i]] = 2;
else
res[ord[i]] = 3;
}
return orig(res);
}
dfs(0, 0);
for (int i = 0; i < n; i++){
if (cnt[i] < a || n - cnt[i] < b) continue;
dfs2(i, i, par[i]);
for (int j = 0; j < a; j++) res[ord2[j]] = 1;
ord2.clear();
dfs2(par[i], par[i], i);
for (int j = 0; j < b; j++) res[ord2[j]] = 2;
for (int j = 0; j < n; j++){
if (res[j] == 0) res[j] = 3;
}
return orig(res);
}
for (int i = 0; i < n; i++){
if (cnt[i] < b || n - cnt[i] < a) continue;
dfs2(i, i, par[i]);
for (int j = 0; j < b; j++) res[ord2[j]] = 2;
ord2.clear();
dfs2(par[i], par[i], i);
for (int j = 0; j < a; j++) res[ord2[j]] = 1;
for (int j = 0; j < n; j++){
if (res[j] == 0) res[j] = 3;
}
return orig(res);
}
return res;
}
/*
7 6
2 2 3
0 1
1 2
2 3
3 4
4 5
5 6
*/
Compilation message (stderr)
split.cpp: In function 'std::vector<int> orig(std::vector<int>)':
split.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# | 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... |