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;
void dfs(vector<vector<int>> &E, vector<bool> &used, vector<int> &d, int v){
d.push_back(v);
for (int w : E[v]){
if (!used[w]){
used[w] = true;
dfs(E, used, d, w);
}
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q){
int m = p.size();
vector<vector<int>> E(n);
for (int i = 0; i < m; i++){
E[p[i]].push_back(q[i]);
E[q[i]].push_back(p[i]);
}
if (a != 1){
for (int i = 0; i < n; i++){
assert(E[i].size() <= 2);
}
int s = 0;
for (int i = 0; i < n; i++){
if (E[i].size() == 1){
s = i;
}
}
vector<bool> used(n, false);
used[s] = true;
vector<int> d;
dfs(E, used, d, s);
vector<int> ans(n);
for (int i = 0; i < a; i++){
ans[d[i]] = 1;
}
for (int i = a; i < a + b; i++){
ans[d[i]] = 2;
}
for (int i = a + b; i < a + b + c; i++){
ans[d[i]] = 3;
}
return ans;
} else {
vector<bool> used(n, false);
used[0] = true;
vector<int> d;
dfs(E, used, d, 0);
vector<int> ans(n);
for (int i = 0; i < b; i++){
ans[d[i]] = 2;
}
ans[d[b]] = 1;
for (int i = b + 1; i < n; i++){
ans[d[i]] = 3;
}
return ans;
}
}
# | 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... |