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;
vector<int> answer;
vector<int> adjList[100005];
int color[100005];
int cnt;
int A,B,C;
void dfs(int u)
{
color[u]=1;
answer[u]=2;
cnt++;
for(int v: adjList[u]){
if(cnt<B){
if(color[v]==0) dfs(v);
}
}
}
void dfs1(int u)
{
color[u]=1;
if(A){
answer[u]=1;
A--;
}
else if(B){
answer[u]=2;
B--;
}
else{
answer[u]=3;
C--;
}
for(int v: adjList[u]){
if(color[v]==0)
dfs1(v);
}
}
vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
int m=p.size();
answer.resize(n);
A=a,B=b,C=c;
for(int i=0;i<m;i++){
adjList[ p[i] ].push_back(q[i]);
adjList[ q[i] ].push_back(p[i]);
}
if(a==1){
dfs(0);
for(int i=0;i<n;i++){
if(answer[i]==0){
if(a){
a--;
answer[i]=1;
}
else answer[i]=3;
}
}
}
else{
int root=0;
for(int i=0;i<n;i++){
if(adjList[i].size()==1){
root=i;
break;
}
}
dfs1(root);
}
return answer;
}
# | 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... |