이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
vp ls = {{a, 1},
{b, 2},
{c, 3}};
sort(all(ls));
vi ans(n);
int rem;
auto solve = [&](auto &solve, int u, int p, int num) -> void {
rem--;
ans[u] = num;
for (int v : G[u]) {
if (!rem) break;
if (v == p) continue;
solve(solve, v, u, num);
}
};
auto dfs = [&](auto &dfs, int u, int p) -> int {
int res = 1;
for (int v : G[u]) {
if (v == p) continue;
int now = dfs(dfs, v, u);
if (ans[0]) break;
res += now;
if (now >= ls[0].first and n - now >= ls[1].first) {
cerr << u << ' ' << v << endl;
rem = ls[0].first;
solve(solve, v, u, ls[0].second);
rem = ls[1].first;
solve(solve, u, v, ls[1].second);
rep(i, n) if (!ans[i]) ans[i] = ls[2].second;
break;
}
if (now >= ls[1].first and n - now >= ls[0].first) {
rem = ls[1].first;
solve(solve, v, u, ls[1].second);
rem = ls[0].first;
solve(solve, u, v, ls[0].second);
rep(i, n) if (!ans[i]) ans[i] = ls[2].second;
}
}
return res;
};
dfs(dfs, 0, -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... |