Submission #291348

#TimeUsernameProblemLanguageResultExecution timeMemory
291348Dremix10Split the Attractions (IOI19_split)C++17
0 / 100
687 ms1048580 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pi; typedef pair<ll,ll> pl; #define F first #define S second #define endl '\n' #define all(x) (x).begin(),(x).end() #ifdef dremix #define p(x) cerr<<#x<<" = "<<x<<endl; #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl; #define pp(x) cerr<<#x<<" = ("<<x.F<<" , "<<x.S<<")"<<endl; #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl; #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl; #else #define p(x) #define p2(x,y) #define pp(x) #define pv(x) #define ppv(x) #endif #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int maxp = 22; const ld EPS = 1e-18; const ll INF = 1e18; const int MOD = 1e9+7; const int N = 2e5+1; vector<vector<int> > adj(N); vector<int> res; bool v[N]; pi siz[3]; int cnt[N]; void dfs(int s, int e){ cnt[s] = 1; for(auto x : adj[s]) if(x!=e){ dfs(x,s); cnt[s] += cnt[x]; } } int curr; int now; void color(int s, int e){ if(now+1>siz[curr-1].F)return; res[s] = siz[curr-1].S; now++; for(auto x : adj[s]) if(x!=e){ color(x,s); } } void solve(int s, int e){ bool flag = false; vector<int> go; for(auto x : adj[s]) if(x!=e && cnt[x]>=siz[curr-1].F){ flag = true; solve(x,s); cnt[s] -= cnt[x]; if(curr==3)return; } else if(x!=e) go.push_back(x); if(cnt[s] >= siz[curr-1].F){ res[s] = siz[curr-1].S; now = 1; for(auto x : go) color(x,s); curr++; } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { siz[0] = {a,1}; siz[1] = {b,2}; siz[2] = {c,3}; sort(siz,siz+3); int i; for(i=0;i<p.size();i++){ int x = p[i],y = q[i]; adj[x].push_back(y); adj[y].push_back(x); } res.assign(n,0); dfs(0,0); curr = 1; solve(0,0); if(curr<3){ for(auto &x : res) x = 0; return res; } for(auto &x : res) if(x==0)x = siz[curr-1].S; return res; }

Compilation message (stderr)

split.cpp: In function 'void solve(int, int)':
split.cpp:61:10: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
   61 |     bool flag = false;
      |          ^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:89:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(i=0;i<p.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...