# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502870 | waynetuinfor | Keys (IOI21_keys) | C++17 | 3093 ms | 25660 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <vector>
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u,
std::vector<int> v, std::vector<int> c) {
int N = r.size(), M = u.size();
std::vector<std::vector<int>> g(N);
std::vector<std::vector<int>> keys(N);
for (int e = 0; e < M; ++e) {
g[u[e]].push_back(e);
g[v[e]].push_back(e);
keys[c[e]].push_back(e);
}
std::vector<bool> vis(N);
std::vector<bool> got(N);
std::vector<int> p(N);
for (int x = 0; x < N; ++x) {
std::fill(vis.begin(), vis.end(), false);
std::fill(got.begin(), got.end(), false);
std::vector<int> que;
auto Push = [&](int p) {
if (got[p]) {
return;
}
got[p] = true;
for (int e : keys[p]) {
if (vis[u[e]] && !vis[v[e]]) {
vis[v[e]] = true;
que.push_back(v[e]);
}
if (vis[v[e]] && !vis[u[e]]) {
vis[u[e]] = true;
que.push_back(u[e]);
}
}
};
vis[x] = true;
que.push_back(x);
for (int it = 0; it < que.size(); ++it) {
int y = que[it];
Push(r[y]);
for (int e : g[y]) {
int z = u[e] ^ v[e] ^ y;
if (got[c[e]] && !vis[z]) {
vis[z] = true;
que.push_back(z);
}
}
}
p[x] = std::count(vis.begin(), vis.end(), true);
}
std::vector<int> res(N);
int t = *std::min_element(p.begin(), p.end());
for (int i = 0; i < N; ++i) {
if (p[i] == t) {
res[i] = 1;
}
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |