이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
vector<int> s, so;
vector<vector<int>> graph;
vector<vector<int>> dfs_tree;
vector<int> depth, mnd;
vector<bool> visited;
vector<int> sz;
void dfs(int nd, int mom, int d = 0){
visited[nd] = 1;
depth[nd] = d, mnd[nd] = d;
for(int x: graph[nd]) if(x != mom && !visited[x]) dfs(x, nd, d+1), sz[nd]+=sz[x];
for(int x: graph[nd]) if(visited[x]) mnd[nd] = min(mnd[nd], depth[x]);
if(mom != -1) dfs_tree[mom].pb(nd);
}
vector<int> ans;
vector<bool> forbidden;
int cnt;
void create_ans(int nd, int id){
if(cnt == 0) return;
ans[nd] = id;
cnt--;
for(int x: dfs_tree[nd]) if(!forbidden[x]) create_ans(x, id);
}
bool found = 0;
void dfs2(int nd){
if(found) return;
int X = sz[nd];
vector<int> rem;
if(X < s[0]) goto end_func;
for(int x: dfs_tree[nd]) if(sz[x] >= s[0]) goto end_func;
for(int x: dfs_tree[nd]) if(mnd[x] < depth[nd] && X-sz[x] >= s[0]) X-=sz[x], rem.pb(x);
if(n-X < s[0]) goto end_func;
found = 1;
if(X >= s[1]){
ans.assign(n, so[2]);
int y = s[0];
for(int x: rem){
y-=sz[x];
cnt = sz[x];
create_ans(x, so[0]);
forbidden[x] = 1;
}
cnt = s[1];
create_ans(nd, so[1]);
cnt = y;
forbidden[nd] = 1;
create_ans(0, so[0]);
}
else{
ans.assign(n, so[2]);
int y = s[1];
for(int x: rem){
y-=sz[x];
cnt = sz[x];
create_ans(x, so[1]);
forbidden[x] = 1;
}
cnt = s[0];
create_ans(nd, so[0]);
cnt = y;
forbidden[nd] = 1;
create_ans(0, so[1]);
}
return;
end_func:
for(int x: dfs_tree[nd]) dfs2(x);
}
vector<int> find_split(int _n, int a, int b, int c, vector<int> U, vector<int> V){
s = {a, b, c}, so = {1, 2, 3};
sort(so.begin(), so.end(), [&](int i, int j){
return s[i-1] < s[j-1];
});
sort(s.begin(), s.end());
swap(n, _n);
m = U.size();
graph.resize(n);
dfs_tree.resize(n);
depth.resize(n);
mnd.assign(n, n);
visited.assign(n, 0);
sz.assign(n, 1);
forbidden.assign(n, 0);
for(int i = 0; i < m; i++){
graph[U[i]].pb(V[i]);
graph[V[i]].pb(U[i]);
}
dfs(0, -1);
dfs2(0);
if(found) return ans;
else return vector<int>(n, 0);
}
# | 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... |