Submission #291366

#TimeUsernameProblemLanguageResultExecution timeMemory
291366Dremix10Split the Attractions (IOI19_split)C++17
0 / 100
668 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 && res[x]==0){ 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 && res[x]==0){ color(x,s); } } int lim; void solve(int s, int e){ for(auto x : adj[s]) if(x!=e && cnt[x]>=siz[curr-1].F && res[x]==0){ solve(x,s); if(curr==lim)return; } if(cnt[s] >= siz[curr-1].F){ res[s] = siz[curr-1].S; now = 1; for(auto x : adj[s]) if(x!=e) 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); //swap(siz[0],siz[1]); 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; lim = 2; solve(0,0); pv(res) if(res[0]){ for(auto &x : res) x = 0; return res; } now = 0; color(0,0); curr++; pv(res) for(auto &x : res) if(x==0)x = siz[curr-1].S; return res; } /* 11 10 3 4 4 0 1 1 3 1 4 1 5 4 6 0 2 2 7 2 8 7 9 9 10 */

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:87:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  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...