Submission #168637

#TimeUsernameProblemLanguageResultExecution timeMemory
168637mhy908Split the Attractions (IOI19_split)C++14
11 / 100
227 ms19240 KiB
#include "split.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define F first #define S second using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const LL llinf=9000000000000000000; const int inf=2000000000; int n, m; vector<int> temp[100010], link[100010]; vector<int> ans; bool ch[100010], DP; int siz[100010], cen=-1, c[100010]; void dfs1(int num){ ch[num]=true; siz[num]=1; for(int i=0; i<temp[num].size(); i++){ if(ch[temp[num][i]])continue; //printf("link : %d %d\n", num, temp[num][i]); link[num].pb(temp[num][i]); link[temp[num][i]].pb(num); dfs1(temp[num][i]); siz[num]+=siz[temp[num][i]]; } } void find_centroid(int num){ if(ch[num])return; bool poss=true; ch[num]=true; for(int i=0; i<link[num].size(); i++){ if(siz[link[num][i]]>n/2)poss=false; } if(poss){ cen=num; return; } for(int i=0; i<link[num].size(); i++){ int tt=siz[link[num][i]]; siz[num]=n-tt; siz[link[num][i]]=n; find_centroid(link[num][i]); if(cen>=0)return; siz[num]=n; siz[link[num][i]]=tt; } } void dfs2(int num, int col){ if(num==cen||c[num])return; c[num]=col; for(int i=0; i<temp[num].size(); i++){ dfs2(temp[num][i], col); } } int dp[100010]; int colored, skipped; void dfs3(int num, int cnt, int p){ if(colored>=cnt||ch[num]||num==cen)return; ch[num]=true; if(skipped==DP-cnt)ans[num]=p; else skipped++; colored++; for(int i=0; i<temp[num].size(); i++){ dfs3(temp[num][i], cnt, p); } } void dfs4(int num, int cnt, int p){ if(colored>=cnt||ans[num])return; ans[num]=p; colored++; for(int i=0; i<temp[num].size(); i++){ dfs4(temp[num][i], cnt, p); } } vector<int> find_split(int _n, int a, int b, int cc, vector<int> p, vector<int> q){ n=_n, m=p.size(); ans.resize(n); for(int i=0; i<m; i++){ temp[p[i]].pb(q[i]); temp[q[i]].pb(p[i]); } dfs1(0); memset(ch, 0, sizeof(ch)); find_centroid(0); int r=0; for(int i=0; i<link[cen].size(); i++){ if(!c[link[cen][i]])dfs2(link[cen][i], ++r); dp[c[link[cen][i]]]+=siz[link[cen][i]]; } bool flag=false; int tonum=0; for(int i=1; i<=r; i++){ if(dp[i]>=min(min(a, b), cc)){ flag=true; tonum=i; DP=dp[i]; } } memset(ch, 0, sizeof(ch)); if(!flag)return ans; for(int i=0; i<link[cen].size(); i++){ if(tonum==c[link[cen][i]]){ if(a<=b&&a<=cc)dfs3(link[cen][i], a, 1); else if(b<=a&&b<=cc)dfs3(link[cen][i], b, 2); else dfs3(link[cen][i], cc, 3); break; } } colored=0; if(a<=b&&a<=cc){ if(b<=cc)dfs4(cen, b, 2); else dfs4(cen, cc, 3); } else if(b<=a&&b<=cc){ if(a<=cc)dfs4(cen, a, 1); else dfs4(cen, cc, 3); } else{ if(a<=b)dfs4(cen, a, 1); dfs4(cen, b, 2); } for(int i=0; i<n; i++){ if(!ans[i]){ if(a<=b&&a<=cc){ if(b<=cc)ans[i]=3; else ans[i]=2; } else if(b<=a&&b<=cc){ if(a<=cc)ans[i]=3; else ans[i]=1; } else{ if(a<=b)ans[i]=2; else ans[i]=1; } } } return ans; } /* 6 7 2 3 1 0 1 1 2 2 3 3 4 4 2 2 5 3 1 */

Compilation message (stderr)

split.cpp: In function 'void dfs1(int)':
split.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<temp[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void find_centroid(int)':
split.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void dfs2(int, int)':
split.cpp:54:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<temp[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void dfs3(int, int, int)':
split.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<temp[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'void dfs4(int, int, int)':
split.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<temp[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:89:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<link[cen].size(); i++){
               ~^~~~~~~~~~~~~~~~~
split.cpp:104:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<link[cen].size(); i++){
               ~^~~~~~~~~~~~~~~~~
#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...