Submission #427753

#TimeUsernameProblemLanguageResultExecution timeMemory
427753PbezzSplit the Attractions (IOI19_split)C++14
0 / 100
1100 ms1048580 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back typedef pair<ll,ll> pii; const ll MAXN = 1e5+5; const ll INF = 1e9+7; vector<vector<ll>>adj(MAXN); int sub[MAXN],cur=1,k,N,chosen=-1,parent; bool visited[MAXN],fine=true; vector<int> des(MAXN); void dfs(ll node, ll p){//cur esta a contar com este visited[node]=true; sub[node]=1; if(!fine)return; bool ok=true; for(auto u:adj[node]){if(!fine)return; if(u==p)continue; dfs(u,node); sub[node]+=sub[u]; if(sub[u]>=k)ok=false; } if(sub[node]>=k&&ok){ chosen=node; parent=p; if(N-sub[node]<k){ fine=false; chosen=-1; } } } int mark,lim,cont; void dfs1(ll node, ll p){ des[node]=mark; for(auto u:adj[node]){ if(u==p)continue; if(cont+1<=lim){cont++; dfs(u,node); } } } vector<int> find_split(int n,int a,int b,int c,vector<int>p,vector<int> q) { int i,m=p.size(); k=min(min(a,b),c); N=n; vector<int> res(n); int meh[3]={a,b,c}; sort(meh,meh+3); for(i=0;i<m;i++){ adj[p[i]].pb(q[i]); adj[q[i]].pb(p[i]); } for(i=0;i<n;i++)res[i]=0; dfs(0,-1); if(chosen==-1)return res; // cout<<chosen<<" "<<parent<<endl; if(sub[chosen]>n-sub[chosen]){ mark=1; cont=0; lim=meh[0]; dfs1(chosen,parent); mark=2; cont=0; lim=meh[1]; dfs1(parent,chosen); }else{ mark=1; cont=0; lim=meh[0]; dfs1(parent,chosen); mark=2; cont=0; lim=meh[1]; dfs1(chosen,parent); } for(i=0;i<n;i++)res[i]=des[i]; if(a<=b&&b<=c){ for(i=0;i<n;i++){ if(res[i]==0){ res[i]=2; } } }else if(a<=c&&c<=b){ for(i=0;i<n;i++){ if(res[i]==0){ res[i]=2; }else if(res[i]==2){ res[i]=3; } } }else if(b<=a&&a<=c){ for(i=0;i<n;i++){ if(res[i]==0){ res[i]=3; }else if(res[i]==1){ res[i]=2; }else{ res[i]=1; } } }else if(b<=c&&c<=a){ for(i=0;i<n;i++){ if(res[i]==0){ res[i]=1; }else if(res[i]==1){ res[i]=2; }else{ res[i]=3; } } }else if(c<=b&&b<=a){ for(i=0;i<n;i++){ if(res[i]==0){ res[i]=1; }else if(res[i]==1){ res[i]=3; }else{ res[i]=3; } } }else{//c<=a<=b for(i=0;i<n;i++){ if(res[i]==0){ res[i]=2; }else if(res[i]==1){ res[i]=3; }else{ res[i]=1; } } } return res; }
#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...