이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
vector<vector<ll>> con(n);
ll m = p.size();
for(ll i = 0;i<m;i++){
con[p[i]].push_back(q[i]);
con[q[i]].push_back(p[i]);
}
ll mxd = 0;
for(auto &o : con) mxd = max(mxd,(ll)o.size());
if (mxd==2){
ll st = 0;
for(ll i = 0;i<n;i++) if(con[i].size()==1) st = i;
vector<ll> v(1,st);
vector<ll> u(n,0);
u[st] = 1;
while(v.size()<n){
for(ll i : con[st]) if(!u[i]){
u[i] = 1;
v.push_back(i);
st = i;
break;
}
}
vector<ll> ret(n,0);
for(ll i = 0;i<a;i++) ret[v[i]] = 1;
for(ll i = a;i<a+b;i++) ret[v[i]] = 2;
for(ll i = a+b;i<a+b+c;i++) ret[v[i]] = 3;
return ret;
}
if (a==1){
vector<ll> r(n,0);
function<void(ll)> dfs;
dfs = [&](ll i){
if (r[i]||b==0) return;
r[i] = 2;
b--;
for(ll j : con[i]){
dfs(j);
}
};
dfs(0);
for(ll i = 0;i<n;i++)if(!r[i]){
if (a){
a=0;
r[i] = 1;
}else r[i] = 3;
}
return r;
}
vector<array<ll,2>> abc = {{a,1},{b,2},{c,3}};
sort(abc.begin(),abc.end());
if(m==n-1){
vector<ll> c1(n,-1),c2(n,-1),s(n,1),P(n,-1);
function<void(ll,ll)> dfs;
dfs = [&](ll i,ll p){
P[i] = p;
for(ll j : con[i])if(j!=p) {
dfs(j,i);
s[i]+=s[j];
}
if (s[i]>=abc[0][0]) c1[i] = 0;
if (s[i]>=abc[1][0]) c2[i] = 0;
for(ll j : con[i])if(j!=p) {
if (c1[j]>=0) c1[i] = max(c1[i],c1[j]+s[i]-s[j]);
if (c2[j]>=0) c2[i] = max(c2[i],c2[j]+s[i]-s[j]);
}
};
dfs(0,-1);
//for(ll i = 0;i<n;i++) cerr << c1[i] << " \n"[i+1==n];
//for(ll i = 0;i<n;i++) cerr << c2[i] << " \n"[i+1==n];
vector<ll> res(n,0);
if (c1[0]<abc[1][0]&&c2[0]<abc[0][0]) return res;
//cerr << "sus\n";
function<void(ll,ll)> draw;
draw = [&](ll i, ll t){
if (abc[t][0]==0||res[i]) return;
abc[t][0]--;
res[i] = abc[t][1];
for(ll j : con[i])if(j!=P[i]) draw(j,t);
};
if (c1[0]>=abc[1][0]){
function<ll(ll)> fd;
fd = [&](ll i){
if (c1[i]==0) return i;
for(ll j : con[i])if(j!=P[i]&&c1[j]+s[i]-s[j]==c1[i]) {
return fd(j);
}
};
ll x = fd(0);
draw(x,0);
draw(0,1);
}else{
function<ll(ll)> fd;
fd = [&](ll i){
if (c2[i]==0) return i;
for(ll j : con[i])if(j!=P[i]&&c2[j]+s[i]-s[j]==c2[i]) {
return fd(j);
}
};
ll x = fd(0);
draw(x,1);
draw(0,0);
}
for(ll i = 0;i<n;i++) if(res[i]==0) res[i] = abc[2][1];
return res;
}
vector<int> res(n,0);
/*if (n == 9) {
res = {1, 1, 3, 1, 2, 2, 3, 1, 3};
} else {
res = {0, 0, 0, 0, 0, 0};
}*/
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:22:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | while(v.size()<n){
| ~~~~~~~~^~
split.cpp: In lambda function:
split.cpp:94:4: warning: control reaches end of non-void function [-Wreturn-type]
94 | };
| ^
split.cpp: In lambda function:
split.cpp:105:4: warning: control reaches end of non-void function [-Wreturn-type]
105 | };
| ^
# | 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... |