Submission #893468

#TimeUsernameProblemLanguageResultExecution timeMemory
893468Faisal_SaqibSplit the Attractions (IOI19_split)C++17
18 / 100
85 ms52816 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N=1e5+2; vector<int> ma[N],ans; bool vis[N]; int n; int sz[N],up[N],h[N]; pair<int,int> comp[3]; bool f=0; void df1(int x,int p) { if(comp[p].first==0) return; vis[x]=1; if(comp[p].first>0) { ans[x]=comp[p].second; comp[p].first--; } for(int y:ma[x]) if(!vis[y] and ans[y]==comp[2].second) df1(y,p); } void dfs(int x,int q=-1) { vis[x]=1; sz[x]=1; bool p=1; vector<int> c; for(int y:ma[x]) { if(!vis[y]) { up[y]=h[y]=h[x]+1; c.push_back(y); dfs(y,x); p&=(sz[y]<comp[0].first); sz[x]+=sz[y]; up[x]=min(up[x],up[y]); } else up[x]=min(up[x],h[y]); } if(p and !f and sz[x]>=comp[0].first) { int P1=sz[x]; int P2=n-P1; vector<int> b; for(int y:c) { if(up[y]<h[x] and (P1-sz[y])>=comp[0].first) P1-=sz[y],P2+=sz[y]; else b.push_back(y); } if(P2>=comp[1].first) { for(int i=0;i<n;i++) vis[i]=0; vis[x]=1; ans[x]=comp[0].second; comp[0].first--; for(auto i:b) df1(i,0); if(q!=-1) df1(q,1); f=1; } } } vector<int> find_split(int n1, int a, int b, int c, vector<int> p, vector<int> q) { n=n1; comp[0]={a,1},comp[1]={b,2},comp[2]={c,3}; sort(comp,comp+3); int m=p.size(); for(int i=0;i<m;i++) ma[p[i]].push_back(q[i]),ma[q[i]].push_back(p[i]); ans.resize(n,comp[2].second); dfs(0); if(!f) for(int i=0;i<n;i++) ans[i]=0; 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...