이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int) 1e5+5
vector<int> ad[MAX_N];
vector<int> res;
vector<bool> vis(MAX_N,0);
vector<pair<int,int>> cnt;
vector<int> sz(MAX_N,0);
vector<int> max_child(MAX_N,0);
int node = -1;
int parent = -1;
void dfs_size(int x,int e){
sz[x] = 1;
max_child[x] = 0;
for(auto s: ad[x]){
if(s == e) continue;
dfs_size(s,x);
sz[x] += sz[s];
max_child[x] = max(max_child[x],sz[s]);
}
}
void dfs1(int x, int e){
if(sz[x] >= cnt[0].first && sz[0] - sz[x] >= cnt[1].second && max_child[x] < cnt[0].first){
node = x;
parent = e;
}
if(sz[x] < cnt[0].first) return;
for(auto s: ad[x]){
if(s == e) continue;
dfs1(s,x);
}
}
void dfs2(int x,int e,int side){
if(cnt[side].first == 0) return;
res[x] = cnt[side].second;
cnt[side].first--;
for(auto s: ad[x]){
if(vis[s] || s == e) continue;
dfs2(s,x,side);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
for(int i = 0;i<(int)p.size();i++){
ad[p[i]].push_back(q[i]);
ad[q[i]].push_back(p[i]);
}
res.assign(n,0);
if(a >= n-1 || b >= n-1 || c>=n-1) return res;
cnt.push_back({a,1});
cnt.push_back({b,2});
cnt.push_back({c,3});
sort(cnt.begin(),cnt.end());
res.assign(n,cnt[2].second);
dfs_size(0,-1);
dfs1(0,-1);
vis[node] = vis[parent] = 1;
if(node == -1) return vector<int>(n,0);
dfs2(node,node,0);
dfs2(parent,parent,1);
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... |