이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I can do all things through Christ who strengthens me
// Philippians 4:13
#include "split.h"
#include "bits/stdc++.h"
using namespace std;
#define REP(i, j, k) for (int i = j; i < (k); i++)
#define RREP(i, j, k) for (int i = j; i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define SZ(x) (int) x.size()
#define ALL(x) x.begin(), x.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 100005;
int n, m, s[3], ss[3];
vi adj[MAXN];
vi ans;
int p[MAXN], rnk[MAXN];
void init() {
REP (i, 0, n) {
p[i] = i;
rnk[i] = 1;
}
}
int findp(int i) {
if (p[i] == i) {
return i;
}
return p[i] = findp(p[i]);
}
bool join(int a, int b) {
int pa = findp(a), pb = findp(b);
if (pa == pb) {
return 0;
}
if (rnk[pa] < rnk[pb]) {
swap(pa, pb);
}
if (rnk[pa] == rnk[pb]) {
rnk[pa]++;
}
p[pb] = pa;
return 1;
}
int sub[MAXN];
int getsub(int u, int p) {
sub[u] = 1;
for (int v : adj[u]) {
if (v == p) {
continue;
}
sub[u] += getsub(v, u);
}
return sub[u];
}
int getcent(int u, int p, int s) {
for (int v : adj[u]) {
if (v == p) {
continue;
}
if (sub[v] > s / 2) {
return getcent(v, u, s);
}
}
return u;
}
void mark(int u, int p, int &rem, int x) {
if (rem == 0) {
return;
}
ans[u] = x;
rem--;
for (int v : adj[u]) {
if (v == p) {
continue;
}
mark(v, u, rem, x);
}
}
vi find_split(int n, int a, int b, int c, vi p, vi q) {
::n = n; s[0] = a; s[1] = b; s[2] = c;
iota(ss, ss + 3, 0);
sort(ss, ss + 3, [&] (int l, int r) {
return s[l] < s[r];
});
m = SZ(p);
init();
REP (i, 0, m) {
if (join(p[i], q[i])) {
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
}
int r = getcent(0, -1, getsub(0, -1));
getsub(r, -1);
ii mx = {-1, -1};
for (int v : adj[r]) {
mxto(mx, {sub[v], v});
}
if (mx.FI < s[ss[0]]) {
return vi(n, 0);
}
ans = vi(n, ss[2] + 1);
mark(mx.SE, r, s[ss[0]], ss[0] + 1);
mark(r, mx.SE, s[ss[1]], ss[1] + 1);
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... |