Submission #891507

#TimeUsernameProblemLanguageResultExecution timeMemory
891507Faisal_SaqibSplit the Attractions (IOI19_split)C++17
40 / 100
74 ms23096 KiB
#include <vector> #include <set> #include <algorithm> using namespace std; const int N=2e5+1; vector<int> ma[N]; int color[N],in[N],sz[N]; bool vis[N]; set<int> one,two; int n; void dfs_sz(int x,int p=-1) { sz[x]=1; for(auto y:ma[x]) { if(y!=p) { dfs_sz(y,x); sz[x]+=sz[y]; } } } bool asd=0; void take(int x,int cnt,bool sp) { vis[x]=1; if(sp) { if(two.size()<cnt) { two.insert(x); } } else { if(one.size()<cnt) { one.insert(x); } } for(auto y:ma[x]) { if(!vis[y]) { take(y,cnt,sp); } } } void find_edge(int x,int a,int b,int p=-1) { vis[x]=1; if(asd) return; for(auto y:ma[x]) { if(!vis[y]) { if(asd) { return; } if(sz[y]>=b and (n-sz[y])>=a) { one.clear(); two.clear(); for(int i=1;i<=n;i++) vis[i]=0; vis[x]=1; take(y,b,1); for(int i=1;i<=n;i++) vis[i]=0; vis[y]=1; take(x,a,0); asd=1; return; } if(sz[y]>=a and (n-sz[y])>=b) { one.clear(); two.clear(); for(int i=1;i<=n;i++) vis[i]=0; vis[x]=1; take(y,a,0); for(int i=1;i<=n;i++) vis[i]=0; vis[y]=1; take(x,b,1); asd=1; return; } sz[x]-=sz[y]; sz[y]+=sz[x]; find_edge(y,a,b,x); sz[y]-=sz[x]; sz[x]+=sz[y]; } } } void dfs(int x,int a,int b) { if(one.size()<a) { one.insert(x); } else if(two.size()<b) { two.insert(x); } vis[x]=1; for(auto y:ma[x]) { if(!vis[y]) { dfs(y,a,b); } } } vector<int> find_split(int n1, int a, int b, int c, vector<int> p, vector<int> q) { n=n1; // Swap a,b,c to make a<=b<=c hold and assign new color to each vector<pair<int,int>> aps; aps.push_back({a,1}); aps.push_back({b,2}); aps.push_back({c,3}); sort(begin(aps),end(aps)); int colora,colorb,colorc; a=aps[0].first; colora=aps[0].second; b=aps[1].first; colorb=aps[1].second; c=aps[2].first; colorc=aps[2].second; // Sorting done // Adding Edges int m=p.size(); int mx=0; for(int j=0;j<m;j++) { p[j]++; q[j]++; ma[p[j]].push_back(q[j]); ma[q[j]].push_back(p[j]); in[p[j]]++; in[q[j]]++; mx=max(mx,in[p[j]]); mx=max(mx,in[q[j]]); } // Edges added if(m==(n-1)) { // Simple as eating ice cream // Find an edge such that if remove it then the two component have size1,size2 // size1>=size2 // size1>=a and size2>=b // then we can make answer dfs_sz(1); find_edge(1,a,b); for(int i=1;i<=n;i++) { color[i]=colorc; } for(auto i:one) { color[i]=colora; } for(auto i:two) { color[i]=colorb; } vector<int> ans; for(int i=1;i<=n;i++) { if(!asd) { ans.push_back(0); } else ans.push_back(color[i]); } return ans; } if(a==1 or mx<=2) { bool pos=1; for(int j=1;j<=n;j++) { if(ma[j].size()==1) { dfs(j,a,b); pos=0; break; } } if(pos) { dfs(1,a,b); } for(int i=1;i<=n;i++) { color[i]=colorc; } for(auto i:two) { color[i]=colorb; } for(auto i:one) { color[i]=colora; } vector<int> ans; for(int i=1;i<=n;i++) { ans.push_back(color[i]); } return ans; } // exit(-1); return {}; }

Compilation message (stderr)

split.cpp: In function 'void take(int, int, bool)':
split.cpp:29:16: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |   if(two.size()<cnt)
      |      ~~~~~~~~~~^~~~
split.cpp:36:16: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if(one.size()<cnt)
      |      ~~~~~~~~~~^~~~
split.cpp: In function 'void dfs(int, int, int)':
split.cpp:102:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |  if(one.size()<a)
      |     ~~~~~~~~~~^~
split.cpp:106:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |  else if(two.size()<b)
      |          ~~~~~~~~~~^~
#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...