이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define P push
#define I insert
vector<int> edges[200000];
int n,m,a,b,c;
int parent[200000];
int subsiz[200000];
vector<int> ans;
void dfs(int x){
subsiz[x]=1;
for(int i=0;i<edges[x].size();i++){
int y=edges[x][i];
if(y==parent[x])continue;
parent[y]=x;
dfs(y);
subsiz[x]+=subsiz[y];
}
}
void colouring(int toall,int nd,int ucol, int unum,int dcol,int dnum){
for(int i=0;i<n;i++)ans[i]=toall;
queue<int> q;q.P(nd);
while(!q.empty() && dnum>0){
int cur=q.front();q.pop();
ans[cur]=dcol;dnum--;
for(int i=0;i<edges[cur].size();i++){
int y=edges[cur][i];
if(y==parent[nd])continue;
q.P(y);
}
}
queue<int> q1;q1.P(parent[nd]);
while(!q1.empty() && unum>0){
int cur=q1.front();q1.pop();
ans[cur]=ucol;unum--;
for(int i=0;i<edges[cur].size();i++){
int y=edges[cur][i];
if(y==nd)continue;
q1.P(y);
}
}
}
void Subtask_1_3(){
parent[0]=0;
dfs(0);
for(int i=0;i<n;i++){
if(subsiz[i]>=a){
if(subsiz[i]-a<=b){colouring(3,i,2,b,1,a);break;}
if(subsiz[i]-a<=c){colouring(2,i,3,c,1,a);break;}
}
if(subsiz[i]>=b){
if(subsiz[i]-b<=a){colouring(3,i,1,a,2,b);break;}
if(subsiz[i]-b<=c){colouring(1,i,3,c,2,b);break;}
}
if(subsiz[i]>=c){
if(subsiz[i]-c<=b){colouring(1,i,2,b,3,c);break;}
if(subsiz[i]-c<=a){colouring(2,i,1,a,3,c);break;}
}
}
return;
}
void Subtask_2(){
bool visited[n];memset(visited,false,sizeof(visited));
queue<int> q;q.P(0);
for(int i=0;i<n;i++)ans[i]=3;
while(!q.empty() && b>0){
int cur=q.front();q.pop();
for(int i=0;i<edges[cur].size();i++){
int y=edges[cur][i];
if(b<=0)break;
if(visited[y])continue;
visited[y]=true;
ans[y]=2;b--;
q.P(y);
}
}
for(int i=0;i<n;i++)if(visited[i]==false){ans[i]=1;break;}
return;
}
vector<int> find_split(int N,int A,int B,int C,vector<int> p,vector<int> q) {
n=N;a=A;b=B;c=C;m=p.size();
for(int i=0;i<n;i++)ans.PB(0);
for(int i=0;i<m;i++){
edges[p[i]].PB(q[i]);
edges[q[i]].PB(p[i]);
}
if(a==1)Subtask_2();
else Subtask_1_3();
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'void dfs(int)':
split.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<edges[x].size();i++){
| ~^~~~~~~~~~~~~~~~
split.cpp: In function 'void colouring(int, int, int, int, int, int)':
split.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<edges[cur].size();i++){
| ~^~~~~~~~~~~~~~~~~~
split.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<edges[cur].size();i++){
| ~^~~~~~~~~~~~~~~~~~
split.cpp: In function 'void Subtask_2()':
split.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i=0;i<edges[cur].size();i++){
| ~^~~~~~~~~~~~~~~~~~
# | 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... |