Submission #299273

#TimeUsernameProblemLanguageResultExecution timeMemory
299273TMJNSplit the Attractions (IOI19_split)C++17
0 / 100
991 ms14712 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; int N; int c[100000],par[100000],t[100000]; bool vis[100000]; vector<int>e[100000],ee[100000]; mt19937 E(869120); vector<int>res; void dfs2(int x){ vis[x]=true; for(int i:ee[x]){ if(!vis[i]){ e[x].push_back(i); e[i].push_back(x); dfs2(i); } } } void make_tree(){ for(int i=0;i<N;i++){ vis[i]=false; for(int j=0;j<ee[i].size();j++){ swap(ee[i][j],ee[i][E()%ee[i].size()]); } } dfs2(E()%N); } void dfs(int x,int from){ par[x]=from; c[x]=1; for(int i:e[x]){ if(i==from)continue; dfs(i,x); c[x]+=c[i]; } } vector<int>find_split(int n,int aaa,int bbb,int ccc,vector<int>p,vector<int>q){ N=n; assert(N<=2500); pair<int,int>P[3]; P[0]={aaa,1}; P[1]={bbb,2}; P[2]={ccc,3}; sort(P,P+3); int m=p.size(); for(int i=0;i<m;i++){ ee[p[i]].push_back(q[i]); ee[q[i]].push_back(p[i]); } for(int _=0;_<3000;_++){ res=vector<int>(n,0); for(int i=0;i<n;i++){ e[i].clear(); t[i]=i; } make_tree(); dfs(0,0); pair<int,int>mn={0xE869120,-1}; for(int i=0;i<n;i++){ if(c[i]>=P[0].first){ mn=min(mn,{c[i],i}); } if(n-c[i]>=P[0].first){ mn=min(mn,{n-c[i],-i}); } } if(mn.second==0){ continue; } else if(mn.second>0){ queue<int>que; que.push(mn.second); res[par[mn.second]]=0xE869120; while(P[0].first){ int x=que.front(); que.pop(); if(!res[x]){ res[x]=P[0].second; P[0].first--; for(int i:e[x]){ que.push(i); } } } res[par[mn.second]]=0; while(!que.empty())que.pop(); que.push(par[mn.second]); while(!que.empty()&&P[1].first){ int x=que.front(); que.pop(); if(!res[x]){ res[x]=P[1].second; P[1].first--; for(int i:e[x]){ que.push(i); } } } if(!P[1].first){ for(int i=0;i<n;i++){ if(!res[i])res[i]=P[2].second; } break; } else{ continue; } } else{ queue<int>que; que.push(par[-mn.second]); res[-mn.second]=0xE869120; while(P[0].first){ int x=que.front(); que.pop(); if(!res[x]){ res[x]=P[0].second; P[0].first--; for(int i:e[x]){ que.push(i); } } } res[-mn.second]=0; while(!que.empty())que.pop(); que.push(-mn.second); while(!que.empty()&&P[1].first){ int x=que.front(); que.pop(); if(!res[x]){ res[x]=P[1].second; P[1].first--; for(int i:e[x]){ que.push(i); } } } if(!P[1].first){ for(int i=0;i<n;i++){ if(!res[i])res[i]=P[2].second; } break; } else{ continue; } } } return res; }

Compilation message (stderr)

split.cpp: In function 'void make_tree()':
split.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |        for(int j=0;j<ee[i].size();j++){
      |                    ~^~~~~~~~~~~~~
#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...