Submission #623028

#TimeUsernameProblemLanguageResultExecution timeMemory
623028TemmieKeys (IOI21_keys)C++17
20 / 100
3070 ms43612 KiB
#include <bits/stdc++.h> struct Dsu { std::vector <int> p; Dsu(int size) { p.resize(size); std::iota(p.begin(), p.end(), 0); } int find(int v) { return v == p[v] ? v : (p[v] = find(p[v])); } void unite(int u, int v) { p[find(u)] = find(v); } }; struct Edge { int u, v, c; }; int n, m; std::vector <Edge> ed; std::vector <std::vector <int>> g; std::vector <int> p; Dsu dsu(0), tree(0); std::vector <int> r; bool go() { std::vector <std::set <int>> keys(n); for (int i = 0; i < n; i++) { keys[dsu.find(i)].insert(r[i]); } std::vector <std::vector <std::pair <int, int>>> eds(n); for (int i = 0; i < n; i++) { for (int x : g[i]) { if (keys[dsu.find(i)].count(ed[x].c)) { eds[dsu.find(i)].emplace_back(ed[x].u ^ ed[x].v ^ i, ed[x].c); } } } bool did = false; for (int i = 0; i < n; i++) { int v = dsu.find(i); if (p[v] != -1) { continue; } for (auto pp : eds[v]) { if (dsu.find(pp.first) == v) { continue; } did = true; if (tree.find(pp.first) == tree.find(v)) { int to = dsu.find(pp.first); p[v] = p[to] = p[v]; dsu.unite(to, v); } else { p[v] = dsu.find(pp.first); tree.unite(pp.first, v); break; } } } return did; } std::vector <int> find_reachable(std::vector <int> _r, std::vector <int> u, std::vector <int> v, std::vector <int> c) { r = _r; n = r.size(); m = c.size(); ed.resize(m); g.resize(n); for (int i = 0; i < m; i++) { g[u[i]].push_back(i); g[v[i]].push_back(i); ed[i] = { u[i], v[i], c[i] }; } p.resize(n, -1); dsu = Dsu(n); tree = Dsu(n); while (go()); std::vector <int> ans(n, 0); for (int i = 0; i < n; i++) { ans[dsu.find(i)] += p[dsu.find(i)] == -1; } int res = 1 << 30; for (int x : ans) { if (x) { res = std::min(res, x); } } std::vector <int> ret(n, 0); for (int i = 0; i < n; i++) { if (ans[dsu.find(i)] == res) { ret[i] = 1; } } return ret; }
#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...