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>
using namespace std;
int N,M,A,B,C, dist[100005];
vector<int> lst[100005], ans;
pair<int,int> tmp[3];
queue<int> Q;
void dfs (int x, int p, int d) {
dist[x] = d;
for (int v: lst[x]) if (v != p) dfs(v,x,d+1);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
N = n, M = p.size(), A = a, B = b, C = c;
for (int i = 0; i < M; ++i) lst[p[i]].push_back(q[i]), lst[q[i]].push_back(p[i]);
dfs(0,-1,0);
pair<int,int> S = make_pair(-1,-1);
for (int i = 0; i < N; ++i) S = max(S,make_pair(dist[i],i));
dfs(S.second,-1,0);
pair<int,int> T = make_pair(-1,-1);
for (int i = 0; i < N; ++i) T = max(T,make_pair(dist[i],i));
tmp[0] = make_pair(A,1), tmp[1] = make_pair(B,2), tmp[2] = make_pair(C,3);
sort(tmp,tmp+3);
ans.assign(N,tmp[2].second);
Q.push(S.second); Q.push(T.second);
ans[S.second] = tmp[1].second, ans[T.second] = tmp[0].second;
int cnt0 = 1, cnt1 = 1;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
if (ans[u] == tmp[0].second && cnt0 >= tmp[0].first) continue;
if (ans[u] == tmp[1].second && cnt1 >= tmp[1].first) continue;
for (int v: lst[u]) if (ans[v] == tmp[2].second) {
ans[v] = ans[u]; Q.push(v);
if (ans[v] == tmp[0].second && ++cnt0 >= tmp[0].first) break;
if (ans[v] == tmp[1].second && ++cnt1 >= tmp[1].first) break;
}
}
if (cnt0 < tmp[0].first || cnt1 < tmp[1].first) return vector<int>(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... |