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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
const int MAXN = 105000;
int n, a, b, c;
vector <pair<int, int>> p;
vector<vector<int>> g;
vector<int> res;
vector <int> sz, par;
void dfs(int v, int p = -1) {
sz[v] = 1;
par[v] = p;
for (int to : g[v]) {
if (to == p) {
continue;
}
dfs(to, v);
sz[v] += sz[to];
}
}
void paint(int v, int bad, int color, int& need) {
// cerr << v << " " << color << " " << need << endl;
if (v == bad || need == 0) {
return;
}
res[v] = color;
need--;
for (int to : g[v]) {
if (to == par[v]) {
continue;
}
paint(to, bad, color, need);
}
}
vector<int> find_split(int N, int A, int B, int C, vector<int> FROM, vector<int> TO) {
n = N; a = A; b = B; c = C;
p = {{a, 1}, {b, 2}, {c, 3}};
g.assign(n + 10, vector<int>());
sz.assign(n + 10, 0);
par.assign(n + 10, 0);
for (int i = 0; i < sz(FROM); i++) {
int from = FROM[i], to = TO[i];
g[from].push_back(to);
g[to].push_back(from);
}
dfs(0);
/* for (int i = 0; i < n; i++) {
cerr << sz[i] << " ";
}
cerr << endl; */
res.assign(n, 0);
sort(all(p));
do {
for (int i = 0; i < n; i++) {
// cerr << sz[i] << " " << n - sz[i] << " " << p[0].first << " " << p[1].first << endl;
if (sz[i] >= p[0].first && n - sz[i] >= p[1].first) {
res.assign(n, p[2].second);
paint(0, i, p[1].second, p[1].first);
paint(i, -1, p[0].second, p[0].first);
return res;
}
}
} while (next_permutation(all(p)));
return res;
}
# | 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... |