This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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];
}
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]);
}
}
getsub(0, -1);
ans = vi(n, ss[2] + 1);
REP (u, 0, n) {
for (int v : adj[u]) {
if (sub[v] > sub[u]) {
continue;
}
if (sub[v] >= s[ss[0]] && n - sub[v] >= s[ss[1]]) {
mark(v, u, s[ss[0]], ss[0] + 1);
mark(u, v, s[ss[1]], ss[1] + 1);
return ans;
}
if (sub[v] >= s[ss[1]] && n - sub[v] >= s[ss[0]]) {
mark(v, u, s[ss[1]], ss[1] + 1);
mark(u, v, s[ss[0]], ss[0] + 1);
return ans;
}
}
}
ans = vi(n, 0);
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... |