Submission #610510

#TimeUsernameProblemLanguageResultExecution timeMemory
610510lorenzoferrariSplit the Attractions (IOI19_split)C++17
18 / 100
100 ms12156 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { array<array<int, 2>, 3> v; v[0] = {a,1}, v[1] = {b,2}, v[2] = {c, 3}; sort(v.begin(), v.end()); array<int, 3> sz{v[0][0], v[1][0], v[2][0]}; array<int, 3> lb{v[0][1], v[1][1], v[2][1]}; array<int, 3> cnt{}; vector<vector<int>> adj(n); for (int i = 0; i < (int)p.size(); ++i) { adj[p[i]].push_back(q[i]); adj[q[i]].push_back(p[i]); } int min_deg = 0; for (int i = 0; i < n; ++i) { if (adj[i].size() < adj[min_deg].size()) { min_deg = i; } } vector<int> ans(n, 0); auto dfs = [&](auto&& self, int v) -> void { if (ans[v] != 0) return; for (int i = 0; i < 3; ++i) { if (cnt[i] < sz[i]) { ++cnt[i]; ans[v] = lb[i]; break; } } for (int u : adj[v]) { self(self, u); } }; dfs(dfs, min_deg); return ans; }
#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...