이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "grader.cpp"
#include "split.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=200010;
vector<int>g[N];
pair<int,int>gr[3];
int sz[N];
void dfs(int v,int pr){
sz[v]=1;
for (int to:g[v]){
if (to!=pr){
dfs(to,v);
sz[v]+=sz[to];
}
}
}
int ans[N];
void Mark(int v,int ind){
if (!gr[ind].first) return;
gr[ind].first--;
ans[v]=gr[ind].second;
// if (!ind) cout<<"OK "<<v<<" "<<gr[ind].first<<" "<<gr[ind].second<<endl;
for (int to:g[v]){
if (ans[to]) continue;
Mark(to,ind);
}
}
bool DONE=false;
void dfs1(int v,int pr){
if (DONE) return;
vector<pair<int,int> >go;
for (int to:g[v]){
if (to!=pr){
go.push_back({sz[to],to});
}
}
sort(go.begin(),go.end());
reverse(go.begin(),go.end());
if (go[0].first>=gr[0].first && go[0].first<=gr[1].first+gr[2].first){
if (go[0].first<=gr[0].first+gr[2].first){
ans[go[0].second]=gr[0].second;
ans[v]=gr[1].second;
Mark(go[0].second,0);
Mark(v,1);
// for (int i=0;i<7;i++) cout<<ans[i]<<" ";
// cout<<endl;
// cout<<"OK "<<v<<" "<<go[0].second<<endl;
} else {
ans[go[0].second]=gr[1].second;
ans[v]=gr[0].second;
Mark(go[0].second,1);
Mark(v,0);
}
DONE=true;
return;
}
if (go[0].first<gr[0].first) return;
dfs1(go[0].first,v);
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
gr[0]={a,1};
gr[1]={b,2};
gr[2]={c,3};
sort(gr,gr+3);
for (int i=0;i<p.size();i++){
g[p[i]].push_back(q[i]);
g[q[i]].push_back(p[i]);
}
if (p.size()==n-1){
dfs(0,-1);
dfs1(0,-1);
if (DONE){
for (int i=0;i<n;i++){
if (!ans[i]) ans[i]=gr[2].second;
}
}
}
vector<int>res;
for (int i=0;i<n;i++) res.push_back(ans[i]);
return res;
}
/**
8 7 2 3 3
0 1
0 2
2 3
2 4
2 5
2 6
2 8
1 2 2 3 3 3 3 3
*/
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i=0;i<p.size();i++){
| ~^~~~~~~~~
split.cpp:71:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
71 | if (p.size()==n-1){
| ~~~~~~~~^~~~~
# | 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... |