Submission #718786

#TimeUsernameProblemLanguageResultExecution timeMemory
718786mseebacherSplit the Attractions (IOI19_split)C++17
22 / 100
496 ms1048576 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; #define MAX_N (int) 1e5+5 vector<int> ad[MAX_N]; vector<int> res; vector<bool> vis(MAX_N,0); vector<pair<int,int>> cnt; vector<int> sz(MAX_N,0); vector<int> max_child(MAX_N,0); int node = -1; int parent = -1; void dfs_size(int x,int e){ sz[x] = 1; max_child[x] = 0; for(auto s: ad[x]){ if(s == e) continue; dfs_size(s,x); sz[x] += sz[s]; max_child[x] = max(max_child[x],sz[s]); } } void dfs1(int x, int e){ if(sz[x] < cnt[0].first) return; if(sz[x] >= cnt[0].first && sz[0] - sz[x] >= cnt[1].first){ node = x; parent = e; return; } if(sz[x] >= cnt[1].first && sz[0] - sz[x] >= cnt[0].first){ parent = x; node = e; return; } for(auto s: ad[x]){ if(s == e) continue; dfs1(s,x); } } void dfs2(int x,int e,int side){ if(cnt[side].first == 0) return; res[x] = cnt[side].second; cnt[side].first--; for(auto s: ad[x]){ if(vis[s] || s == e) continue; dfs2(s,x,side); } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { for(int i = 0;i<(int)p.size();i++){ ad[p[i]].push_back(q[i]); ad[q[i]].push_back(p[i]); } res.assign(n,0); if(a >= n-1 || b >= n-1 || c>=n-1) return res; cnt.push_back({a,1}); cnt.push_back({b,2}); cnt.push_back({c,3}); sort(cnt.begin(),cnt.end()); res.assign(n,cnt[2].second); dfs_size(0,-1); dfs1(0,-1); if(node == -1) return vector<int>(n,0); vis[node] = vis[parent] = 1; dfs2(node,node,0); dfs2(parent,parent,1); return res; }
#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...