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 rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); i++)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
vi find_split(int n, int a, int b, int c, vi p, vi q) {
vvi G(n);
rep(i, p.size()) {
G[p[i]].pb(q[i]);
G[q[i]].pb(p[i]);
}
vi ord = {1, 2, 3};
rep(_, 2) {
rep(__, 3) {
vi ls;
vi in(n), out(n);
P dif(0, 0);
P same(0, 0);
auto dfs = [&](auto &dfs, int u, int p) -> P {
in[u] = ls.size();
ls.pb(u);
P res(0, 0);
for (int v : G[u]) {
if (v == p) continue;
P now = dfs(dfs, v, u);
if (now.first and res.second) {
dif = {now.first, res.second};
}
if (now.second and res.first) {
dif = {res.first, now.second};
}
if(now.first) res.first = now.first;
if(now.second) res.second = now.second;
}
out[u] = ls.size();
if (out[u] - in[u] == b) res.first = u + 1;
if (out[u] - in[u] == c) res.second = u + 1;
if (out[u] - in[u] == b + c) {
if (res.second) {
same = {u + 1, res.second};
}
}
return res;
};
dfs(dfs, 0, -1);
if (dif.first) {
dif.first--, dif.second--;
vi ans(n);
rep2(i, in[dif.first], out[dif.first]) ans[ls[i]] = ord[1];
rep2(i, in[dif.second], out[dif.second]) ans[ls[i]] = ord[2];
rep(i, n) if (!ans[i]) ans[i] = ord[0];
return ans;
}
if (same.first) {
same.first--, same.second--;
vi ans(n);
rep2(i, in[same.second], out[dif.second]) ans[ls[i]] = ord[2];
rep2(i, in[same.first], out[same.first]) if (!ans[ls[i]]) ans[ls[i]] = ord[1];
rep(i, n) if (!ans[i]) ans[i] = ord[0];
return ans;
}
swap(a, b);
swap(ord[0], ord[1]);
swap(b, c);
swap(ord[1], ord[2]);
}
swap(a, b);
swap(ord[0], ord[1]);
}
return vi(n, 0);
}
# | 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... |