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;
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
array<array<int, 2>, 3> v;
v[0] = {a,1}, v[1] = {b,2}, v[2] = {c, 3};
sort(v.begin(), v.end());
array<int, 3> sz{v[0][0], v[1][0], v[2][0]};
array<int, 3> lb{v[0][1], v[1][1], v[2][1]};
array<int, 3> cnt{};
vector<vector<int>> adj(n);
for (int i = 0; i < (int)p.size(); ++i) {
adj[p[i]].push_back(q[i]);
adj[q[i]].push_back(p[i]);
}
int min_deg = 0;
for (int i = 0; i < n; ++i) {
if (adj[i].size() < adj[min_deg].size()) {
min_deg = i;
}
}
vector<int> ans(n, 0);
auto dfs = [&](auto&& self, int v) -> void {
if (ans[v] != 0) return;
for (int i = 0; i < 3; ++i) {
if (cnt[i] < sz[i]) {
++cnt[i];
ans[v] = lb[i];
break;
}
}
for (int u : adj[v]) {
self(self, u);
}
};
dfs(dfs, min_deg);
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... |