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>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
using namespace std;
void dfs(int v, vector<vector<int>> &g, vector<bool> &used, vector<int> &vec, int need) {
if (sz(vec) >= need) return;
if (used[v]) return;
used[v] = 1;
vec.push_back(v);
for (int &u : g[v]) {
if (used[u]) continue;
dfs(u, g, used, vec, need);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
int m = sz(p);
vector<int> res(n);
vector<int> deg(n);
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
deg[p[i]]++;
deg[q[i]]++;
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
int vert = 0;
for (int i = 0; i < n; i++) {
if (deg[i] < deg[vert]) {
vert = i;
}
}
vector<int> v = {0, a, b, c};
vector<int> perm = {1, 2, 3};
sort(all(perm), [&](int i, int j){
return v[i] < v[j];
});
vector<bool> used(n);
vector<int> A;
dfs(vert, g, used, A, v[perm[0]]);
assert(sz(A) == v[perm[0]]);
for (int &i : A) {
res[i] = perm[0];
}
int unused = -1;
for (int v = 0; v < n; v++) {
if (!used[v]) {
unused = v;
}
}
assert(unused != -1);
vector<int> B;
dfs(unused, g, used, B, v[perm[1]]);
assert(sz(B) == v[perm[1]]);
for (int &i : B) {
res[i] = perm[1];
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
res[i] = perm[2];
}
}
return res;
}
/*
9 10
4 2 3
0 1
0 2
0 3
0 4
0 6
0 8
1 7
3 7
4 5
5 6
*/
/*
g++ -std=gnu++14 -O2 -Wall -pipe -static -o "split" "grader.cpp" "split.cpp"
*/
# | 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... |