Submission #168672

#TimeUsernameProblemLanguageResultExecution timeMemory
168672mhy908Split the Attractions (IOI19_split)C++14
40 / 100
187 ms19192 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]; 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, kkk; bool chlink[100010]; void dfs3(int num, int pp, int ccc){ if(ch[num]||num==cen)return; ch[num]=true; if(colored<pp){ ans[num]=ccc; colored++; } for(int i=0; i<link[num].size(); i++){ dfs3(link[num][i], pp, ccc); } } 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; } } if(!flag)return ans; memset(ch, 0, sizeof(ch)); 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); chlink[i]=true; if(colored==min(min(a, b), cc))break; } } if(a<=b&&a<=cc){ if(b<=cc)ans[cen]=2; else ans[cen]=3; } else if(b<=a&&b<=cc){ if(a<=cc)ans[cen]=1; else ans[cen]=3; } else{ if(a<=b)ans[cen]=1; else ans[cen]=2; } colored=1; for(int i=0; i<link[cen].size(); i++){ if(chlink[i])continue; if(a<=b&&a<=cc){ if(b<=cc)dfs3(link[cen][i], b, 2); else dfs3(link[cen][i], cc, 3); } else if(b<=a&&b<=cc){ if(a<=cc)dfs3(link[cen][i], a, 1); else dfs3(link[cen][i], cc, 3); } else{ if(a<=b)dfs3(link[cen][i], a, 1); else dfs3(link[cen][i], 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:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:83:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<link[cen].size(); i++){
               ~^~~~~~~~~~~~~~~~~
split.cpp:97:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<link[cen].size(); i++){
               ~^~~~~~~~~~~~~~~~~
split.cpp:119: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...