Submission #296498

#TimeUsernameProblemLanguageResultExecution timeMemory
296498b00n0rpSplit the Attractions (IOI19_split)C++17
40 / 100
181 ms28536 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define pb push_back #define REP(i,n) for(int i = 0; i < n; i++) #define FOR(i,a,b) for(int i = a; i < b; i++) #define pii pair<int,int> #define F first #define S second using namespace std; const int MX = 200005; vi g[MX],adj[MX]; int par[MX],dep[MX],sz[MX]; pii A[MX]; bitset<MX> vis; vi ans; void dfs(int u,int p,int d = 0){ par[u] = p; vis[u] = 1; dep[u] = d; sz[u] = 1; for(auto v:g[u]){ if(vis[v]) continue; adj[u].pb(v); adj[v].pb(u); dfs(v,u,d-1); sz[u] += sz[v]; } } void assign(int u,int val){ vis[u] = 1; if(A[val].F){ ans[u] = A[val].S; A[val].F--; } else ans[u] = A[2].S; for(auto v:adj[u]){ if(!vis[v]) assign(v,val); } } vi find_split(int n, int a, int b, int c, vi p, vi q) { A[0] = {a,1}; A[1] = {b,2}; A[2] = {c,3}; sort(A,A+3); ans.resize(n); REP(i,(int)p.size()){ g[p[i]].pb(q[i]); g[q[i]].pb(p[i]); } dfs(0,0); vis.reset(); REP(i,n){ if(sz[i] >= A[0].F and n-sz[i] >= A[0].F){ vis[i] = 1; if(sz[i] < n-sz[i]){ assign(par[i],1); assign(i,0); } else{ assign(par[i],0); assign(i,1); } return ans; } } return vi(n,0); }
#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...