Submission #1019900

#TimeUsernameProblemLanguageResultExecution timeMemory
1019900aufanKeys (IOI21_keys)C++17
37 / 100
3055 ms44224 KiB
#include <bits/stdc++.h> using namespace std; vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n = (int)r.size(), m = (int)u.size(); vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; i++) { g[u[i]].push_back({v[i], c[i]}); g[v[i]].push_back({u[i], c[i]}); } vector<int> par(n); iota(par.begin(), par.end(), 0); function<int(int)> root = [&](int x) { return par[x] == x ? x : par[x] = root(par[x]); }; vector<int> vis(n), done(n), q(n), p(n, n + 1); vector<vector<int>> pend(n); auto bfs = [&](int s, int upd) { int ptr = 0, ret = -1; vis[s] = 1; q[ptr++] = s; for (int i = 0; i < ptr; i++) { int x = q[i]; if (!done[r[x]]) { done[r[x]] = 1; for (auto z : pend[r[x]]) { if (root(z) != s) { ret = root(z); } if (!vis[z]) { vis[z] = 1; q[ptr++] = z; } } pend[r[x]].clear(); } for (auto [z, y] : g[x]) { if (!done[y]) { pend[y].push_back(z); } else { if (root(z) != s) { ret = root(z); } if (!vis[z]) { vis[z] = 1; q[ptr++] = z; } } } if (ret != -1) break; } for (int i = 0; i < ptr; i++) { int x = q[i]; vis[x] = 0; done[r[x]] = 0; for (auto [z, y] : g[x]) { pend[y].clear(); } } if (upd) { for (int i = 0; i < ptr; i++) { int x = q[i]; p[x] = ptr; } } return ret; }; for (int _ = 0; _ < 20; _++) { vector<int> ok(n, 0); for (int i = 0; i < n; i++) { if (root(i) == i && !ok[i]) { int j = bfs(i, 0); if (j != -1) { par[i] = j; ok[j] = 1; } } } } for (int i = 0; i < n; i++) { if (root(i) == i) { bfs(i, 1); } } int mn = *min_element(p.begin(), p.end()); vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = (p[i] == mn); 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...