Submission #1047735

#TimeUsernameProblemLanguageResultExecution timeMemory
1047735Kel_MahmutSplit the Attractions (IOI19_split)C++14
40 / 100
42 ms14420 KiB
#include "split.h" #include <bits/stdc++.h> #define pb push_back // #define endl ("\n") #define all(aa) aa.begin(), aa.end() typedef long long ll; using namespace std; vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { int m = q.size(); vector<vector<int>> g(n); for(int i = 0; i < m; i++){ g[q[i]].pb(p[i]); g[p[i]].pb(q[i]); } bool chain = 1; for(int i = 0; i < n; i++) chain &= (int) g[i].size() <= 2; if(chain){ vector<int> vis(n); vector<int> color(n); int lim = 0; int cnt = 0; int komsu; function<void(int, int)> dfs = [&](int u, int col){ cnt++; color[u] = col; vis[u] = 1; if(cnt == lim){ for(int v : g[u]){ if(!vis[v]){ komsu = v; return; } } komsu = -1; return; } for(int v : g[u]){ if(vis[v]) continue; dfs(v, col); if(cnt == lim) return; } }; vector<int> deg1; for(int i = 0; i < n; i++) if(g[i].size() == 1) deg1.pb(i); lim = a; cnt = 0; if(deg1.size()) dfs(deg1[0], 1); else{ for(int i = 0; i < n; i++){ if(!vis[i]){ dfs(i, 1); break; } } } lim = b; cnt = 0; if(deg1.size()) dfs(deg1[1], 2); else{ assert(komsu != -1); dfs(komsu, 2); } lim = c; cnt = 0; for(int i = 0; i < n; i++){ if(!vis[i]){ dfs(i, 3); break; } } return color; } if(a == 1){ vector<int> vis(n); vector<int> color(n); int lim = b; int cnt = 0; function<void(int, int)> dfs = [&](int u, int col){ cnt++; vis[u] = 1; color[u] = col; if(cnt == lim) return; for(int v : g[u]){ if(vis[v]) continue; dfs(v, col); if(cnt == lim) return; } }; dfs(0, 2); for(int i = 0; i < n; i++){ if(!vis[i]){ vis[i] = 1; color[i] = 1; break; } } for(int i = 0; i < n; i++){ if(!vis[i]){ vis[i] = 1; color[i] = 3; } } return color; } if(m == n - 1){ vector<pair<int, int>> sorted; sorted.pb({a, 1}); sorted.pb({b, 2}); sorted.pb({c, 3}); sort(all(sorted)); vector<int> sub(n); vector<int> color(n); int start = -1, parent = -1; function<int(int, int)> subsize = [&](int u, int par){ sub[u] = 1; for(int v : g[u]){ if(v == par) continue; sub[u] += subsize(v, u); if(sub[v] >= sorted[0].first && (n - sub[v]) >= sorted[1].first){ start = v; parent = u; } if(sub[v] >= sorted[1].first && (n - sub[v]) >= sorted[0].first){ start = u; parent = v; } } return sub[u]; }; subsize(0, -1); int cnt = 0; int lim = sorted[0].first; function<void(int, int, int)> fill = [&](int u, int par, int col){ color[u] = col; cnt++; if(cnt >= lim) return; for(int v : g[u]){ if(v == par) continue; fill(v, u, col); if(cnt >= lim) return; } }; if(start == -1 && parent == -1){ for(int i = 0; i < n; i++) color[i] = 0; return color; } fill(start, parent, sorted[0].second); assert(cnt == lim); lim = sorted[1].first; cnt = 0; fill(parent, start, sorted[1].second); assert(cnt == lim); for(int i = 0; i < n; i++){ if(color[i]) continue; color[i] = sorted[2].second; } return color; } }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:13:25: warning: control reaches end of non-void function [-Wreturn-type]
   13 |  vector<vector<int>> g(n);
      |                         ^
#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...