이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
int sz[100005], par[100005], out[100005];
bool vis[100005];
vector<int> adj[100005];
int get_sz(int u, int e = -1) {
sz[u] = 1;
for (auto v : adj[u]) if (v != e) {
par[v] = u;
sz[u] += get_sz(v, u);
}
return sz[u];
}
void mark_all(int u, int col, int e = -1) {
out[u] = col;
for (auto v : adj[u]) if (v != e) {
mark_all(v, col, u);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
int m = (int)p.size();
for (int i = 0; i < m; i++) {
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
get_sz(0);
int root = -1, split_point = -1;
for (int i = 0; i < n; i++) {
for (auto [d, col] : {mp(&a, 1), mp(&b, 2), mp(&c, 3)}) {
if (sz[i] == *d) {
root = 0;
split_point = i;
mark_all(i, col, par[i]);
*d = 0;
break;
}
if (n - sz[i] == *d) {
root = i;
split_point = par[i];
mark_all(par[i], col, i);
*d = 0;
break;
}
}
}
if (root == -1) {
return vector<int>(n, 0);
}
queue<int> Q;
int cnt = 0;
Q.push(root);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (auto v : adj[u]) if (!vis[v] && v != split_point) {
vis[v] = 1;
Q.push(v);
cnt++;
if (cnt == max({a, b, c})) {
for (int i = 0; i < n; i++) {
if (vis[i]) {
out[i] = max({mp(a, 1), mp(b, 2), mp(c, 3)}).second;
}
}
goto done;
}
}
}
done:;
set<int> used;
for (int i = 0; i < n; i++) {
if (out[i]) {
used.insert(out[i]);
}
}
assert((int)used.size() == 2);
int tmp = 0;
for (int i : used) {
tmp ^= i;
}
for (int i = 0; i < n; i++) {
if (out[i] == 0) {
out[i] = tmp;
}
}
vector<int> real_out;
for (int i = 0; i < n; i++) {
real_out.pb(out[i]);
}
return real_out;
}
# | 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... |