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<bits/stdc++.h>
#define MAXN 100007
using namespace std;
int n,m,li[MAXN],tim,sz[MAXN];
pair<int,int> s[3];
vector<int> v[MAXN],ans;
int in[MAXN],cnt;
int sol[MAXN];
bool vis[MAXN];
void mark(int x,int val,int id){
if(s[id].first==0)return;
vis[x]=true;
sol[x]=s[id].second;
s[id].first--;
for(int i:v[x]){
if(vis[i])continue;
if(in[i]==val or in[i]==val+1)mark(i,val,id);
}
}
bool dfs(int x,int p){
li[x]=tim; sz[x]=1; in[x]=1;
for(int i=0;i<v[x].size();i++){
if(li[v[x][i]]==tim)continue;
if(dfs(v[x][i],x))return true;
sz[x]+=sz[v[x][i]];
}
in[x]=2;
if(sz[x]>=s[0].first and n-sz[x]>=s[1].first){
mark(x,2,0);
mark(p,0,1);
return true;
}
if(sz[x]>=s[1].first and n-sz[x]>=s[0].first){
mark(x,2,1);
mark(p,0,0);
return true;
}
return false;
}
vector<int> find_split(int N, int A, int B, int C,vector<int> p,vector<int> q){
n=N; m=int(p.size());
s[0]={A,1}; s[1]={B,2}; s[2]={C,3};
sort(s,s+3);
for(int i=1;i<=m;i++){
v[p[i-1]+1].push_back(q[i-1]+1);
v[q[i-1]+1].push_back(p[i-1]+1);
}
ans.resize(n);
return ans;
for(int i=1;i<=n;i++){
for(int f=1;f<=n;f++)in[f]=0;
tim++;
if(dfs(i,0))break;
if(i==n)return ans;
}
for(int i=1;i<=n;i++){
if(sol[i]==0)sol[i]=s[2].second;
}
for(int i=1;i<=n;i++)ans[i-1]=sol[i];
return ans;
}
/*int main(){
ans=find_split(9, 4, 2, 3, {0, 0, 0, 0, 0, 0, 1, 3, 4, 5},{1, 2, 3, 4, 6, 8, 7, 7, 5, 6});
for(int i:ans){
cout<<i<<" ";
}
return 0;
}*/
Compilation message (stderr)
split.cpp: In function 'bool dfs(int, int)':
split.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<v[x].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... |