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 FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define pb push_back
using namespace std;
typedef vector<int> vi;
const int MxN=1e5+10;
int n, m, dp[MxN], s[3];
vi ad[MxN];
void pre(int u, int pst=-1) {
dp[u]=1;
for(auto it : ad[u]) {
if(it==pst) continue;
pre(it, u);
dp[u]+=dp[it];
}
}
int x=-1, y=-1;
void dfs(int u, int pst=-1, int up=0) {
if(up>=s[0] && dp[u]>=s[1]) {
x=pst; y=u;
}
else if(up>=s[1] && dp[u]>=s[0]) {
x=u; y=pst;
}
for(auto it : ad[u]) {
if(it==pst) continue;
dfs(it, u, up+dp[u]-dp[it]);
}
}
vi ans;
void spread(int u, int in, int pst=-1) {
s[in]--;
ans[u]=in+1;
// cout << u << " -> " << in << endl;
if(s[in]==0) return;
// cout << pst << "\n";
// for(auto it : ad[5]){
// cout << it << " ";
// }
// cout << endl;
for(auto it : ad[u]) {
if(it==pst) continue;
spread(it, in, u);
if(s[in]==0) return;
}
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
n=N; m=p.size();
vi tmp; tmp.pb(a); tmp.pb(b); tmp.pb(c);
//sort(tmp.begin(), tmp.end());
FOR(z, 0, 3) s[z]=tmp[z];
FOR(i, 0, m) {
ad[p[i]].pb(q[i]);
ad[q[i]].pb(p[i]);
}
pre(0);
dfs(0);
FOR(i, 0, n) ans.pb(0);
if(x==-1) return ans;
FOR(i, 0, n) ans[i]=3;
spread(x, 0, y);
spread(y, 1, x);
// cout << x << " " << y << ": " << rev << endl;
// cout << s[0] << " " << s[1] << endl;
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... |