#include "split.h"
#include <bits/stdc++.h>
using namespace std;
int c[100000],par[100000];
vector<int>e[100000];
vector<int>res;
void dfs(int x,int from){
par[x]=from;
c[x]=1;
for(int i:e[x]){
if(i==from)continue;
dfs(i,x);
c[x]+=c[i];
}
}
vector<int>find_split(int n,int aaa,int bbb,int ccc,vector<int>p,vector<int>q){
res=vector<int>(n,0);
pair<int,int>P[3];
P[0]={aaa,1};
P[1]={bbb,2};
P[2]={ccc,3};
sort(P,P+3);
for(int i=0;i<p.size();i++){
e[p[i]].push_back(q[i]);
e[q[i]].push_back(p[i]);
}
if(P[0].first==1){
queue<int>que;
que.push(0);
while(P[1].first){
int x=que.front();
que.pop();
if(res[x])continue;
res[x]=P[1].second;
P[1].first--;
for(int i:e[x]){
que.push(i);
}
}
for(int i=0;i<n;i++){
if(!res[i]){
res[i]=P[0].second;
break;
}
}
for(int i=0;i<n;i++){
if(!res[i]){
res[i]=P[2].second;
}
}
}
else if(p.size()==n-1){
dfs(0,0);
pair<int,int>mn={0xE869120,-1};
for(int i=0;i<n;i++){
if(c[i]>=P[0].first){
mn=min(mn,{c[i],i});
}
if(n-c[i]>=P[0].first){
mn=min(mn,{n-c[i],-i});
}
}
if(mn.second==0){
}
else if(mn.second>0){
queue<int>que;
que.push(mn.second);
res[par[mn.second]]=0xE869120;
while(P[0].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[0].second;
P[0].first--;
for(int i:e[x]){
que.push(i);
}
}
}
res[par[mn.second]]=0;
while(!que.empty())que.pop();
que.push(par[mn.second]);
while(!que.empty()&&P[1].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[1].second;
P[1].first--;
for(int i:e[x]){
que.push(i);
}
}
}
if(!P[1].first){
for(int i=0;i<n;i++){
if(!res[i])res[i]=P[2].second;
}
}
else{
for(int i=0;i<n;i++){
res[i]=0;
}
}
}
else{
queue<int>que;
que.push(par[-mn.second]);
res[-mn.second]=0xE869120;
while(P[0].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[0].second;
P[0].first--;
for(int i:e[x]){
que.push(i);
}
}
}
res[-mn.second]=0;
while(!que.empty())que.pop();
que.push(-mn.second);
while(!que.empty()&&P[1].first){
int x=que.front();
que.pop();
if(!res[x]){
res[x]=P[1].second;
P[1].first--;
for(int i:e[x]){
que.push(i);
}
}
}
if(!P[1].first){
for(int i=0;i<n;i++){
if(!res[i])res[i]=P[2].second;
}
}
else{
for(int i=0;i<n;i++){
res[i]=0;
}
}
}
}
if(p.size()==n){
queue<int>que;
que.push(0);
while(P[0].first){
int x=que.front();
que.pop();
if(!res[x]){
P[0].first--;
res[x]=P[0].second;
for(int i:e[x]){
que.push(i);
}
}
}
while(!que.empty())que.pop();
for(int i=0;i<n;i++){
if(!res[i]){
que.push(i);
while(P[1].first){
int x=que.front();
que.pop();
if(!res[x]){
P[1].first--;
res[x]=P[1].second;
for(int j:e[x]){
que.push(j);
}
}
}
break;
}
}
for(int i=0;i<n;i++){
if(!res[i])res[i]=P[2].second;
}
}
return res;
}
Compilation message
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
split.cpp:55:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | else if(p.size()==n-1){
| ~~~~~~~~^~~~~
split.cpp:149:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
149 | if(p.size()==n){
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
ok, correct split |
2 |
Runtime error |
5 ms |
5160 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
ok, correct split |
2 |
Runtime error |
6 ms |
5248 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
ok, correct split |
2 |
Correct |
89 ms |
9080 KB |
ok, correct split |
3 |
Correct |
28 ms |
5496 KB |
ok, correct split |
4 |
Correct |
2 ms |
2688 KB |
ok, correct split |
5 |
Correct |
97 ms |
11000 KB |
ok, correct split |
6 |
Correct |
100 ms |
10744 KB |
ok, correct split |
7 |
Correct |
105 ms |
10616 KB |
ok, correct split |
8 |
Correct |
98 ms |
11768 KB |
ok, correct split |
9 |
Correct |
108 ms |
10488 KB |
ok, correct split |
10 |
Correct |
24 ms |
4864 KB |
ok, no valid answer |
11 |
Correct |
35 ms |
6016 KB |
ok, no valid answer |
12 |
Correct |
67 ms |
9332 KB |
ok, no valid answer |
13 |
Correct |
78 ms |
9080 KB |
ok, no valid answer |
14 |
Correct |
62 ms |
9408 KB |
ok, no valid answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
jury found a solution, contestant did not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
ok, correct split |
2 |
Runtime error |
5 ms |
5160 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |