This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[cur])continue;
q.P(y);
}
}
bool visited[n];memset(visited,false,sizeof(visited));
visited[parent[nd]]=true;
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 || visited[y])continue;
q1.P(y);
visited[y]=true;
}
}
}
void Subtask_1_3(){
parent[0]=0;
dfs(0);
for(int i=0;i<n;i++)cout<<subsiz[i]<<" ";cout<<endl;
for(int i=0;i<n;i++){
if(subsiz[i]>=a){
if(n-subsiz[i]>=b){colouring(3,i,2,b,1,a);break;}
if(n-subsiz[i]>=c){colouring(2,i,3,c,1,a);break;}
}
if(subsiz[i]>=b){
if(n-subsiz[i]>=a){colouring(3,i,1,a,2,b);break;}
if(n-subsiz[i]>=c){colouring(1,i,3,c,2,b);break;}
}
if(subsiz[i]>=c){
if(n-subsiz[i]>=b){colouring(1,i,2,b,3,c);break;}
if(n-subsiz[i]>=a){colouring(2,i,1,a,3,c);break;}
}
}
return;
}
void Subtask_2(){
bool visited[n];memset(visited,false,sizeof(visited));
for(int i=0;i<n;i++)ans[i]=3;
visited[0]=true;ans[0]=2;b--;
queue<int> q;q.P(0);
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(visited[y])continue;
if(b<=0)break;
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;
}
Compilation message (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:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<edges[cur].size();i++){
| ~^~~~~~~~~~~~~~~~~~
split.cpp: In function 'void Subtask_1_3()':
split.cpp:54:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
54 | for(int i=0;i<n;i++)cout<<subsiz[i]<<" ";cout<<endl;
| ^~~
split.cpp:54:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
54 | for(int i=0;i<n;i++)cout<<subsiz[i]<<" ";cout<<endl;
| ^~~~
split.cpp: In function 'void Subtask_2()':
split.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | 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... |