제출 #891475

#제출 시각아이디문제언어결과실행 시간메모리
891475UmairAhmadMirzaSplit the Attractions (IOI19_split)C++17
18 / 100
55 ms16496 KiB
#include <bits/stdc++.h> using namespace std; int const N=1e5+5; vector<int> adj[N]; int col[N]; bool vis[N]; int cnt=0; int aa=0,bb=0,cc=0; int col_seq[3]={1,2,3}; int sz[N]; void dfs(int node){ if(cnt==bb) return; vis[node]=1; col[node]=2; cnt++; for(auto i:adj[node]) if(!vis[i]) dfs(i); } void dfs1(int node){ if(cnt==aa || col[node]!=3) return; vis[node]=1; col[node]=1; cnt++; for(auto i:adj[node]) if(!vis[i]) dfs1(i); } void fill_all(int node,int par){ if(cnt<=0) return; col[node]=col_seq[0]; cnt--; for(auto i:adj[node]) if(i!=par) fill_all(i,node); } int mini=N; int found=-1; int par_found=0; void sub(int node,int par){ sz[node]=1; for(auto i:adj[node]) if(i!=par){ sub(i,node); sz[node]+=sz[i]; } if(sz[node]>=aa && sz[node]<mini){ mini=sz[node]; found=node; par_found=par; } } bool free_vis[N]; int cnt_free(int node,int par){ if(col[node]==col_seq[0]) return 0; int c=1; free_vis[node]=1; for(auto i:adj[node]) if(i!=par) c+=cnt_free(i,node); return c; } void fill_it(int node,int par){ if(cnt<=0) return; if(col[node]==col_seq[0]) return; col[node]=col_seq[1]; cnt--; for(auto i:adj[node]) if(i!=par) fill_it(i,node); } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q){ int m=p.size(); for (int i = 0; i < m; ++i) { adj[p[i]].push_back(q[i]); adj[q[i]].push_back(p[i]); } aa=a; bb=b; cc=c; for (int i = 0; i < n; ++i) col[i]=3; vector<int> ans; if(a==1){ dfs(0); for (int i = 0; i < n; ++i) if(col[i]==3){ col[i]=1; break; } } else if(m==n-1){ if(aa>bb){ swap(aa,bb); swap(col_seq[0],col_seq[1]); } if(cc<bb){ swap(cc,bb); swap(col_seq[1],col_seq[2]); } if(aa>bb){ swap(aa,bb); swap(col_seq[0],col_seq[1]); } for (int i = 0; i < n; ++i) col[i]=col_seq[2]; cnt=aa; sub(0,-1); fill_all(found,par_found); bool done=0; for (int i = 0; i < n; ++i) if(free_vis[i]==0 && cnt_free(i,-1)>=bb){ cnt=bb; fill_it(i,-1); done=1; } if(done==0){ for (int i = 0; i < n; ++i) ans.push_back(0); return ans; } } else{ int u=0; for (int i = 0; i < n; ++i) if(adj[i].size()==1) u=i; dfs(u); for (int i = 0; i < n; ++i) if(vis[i]==0) u=i; cnt=0; dfs1(u); } for (int i = 0; i < n; ++i) ans.push_back(col[i]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...