# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
986982 | pedroslrey | Keys (IOI21_keys) | C++17 | 3019 ms | 27588 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 <bits/stdc++.h>
#include "keys.h"
using namespace std;
vector<int> find_reachable(vector<int> rs, vector<int> us, vector<int> vs, vector<int> cs) {
int n = rs.size();
vector<vector<pair<int, int>>> graph(n);
for (int i = 0; i < us.size(); ++i) {
graph[us[i]].emplace_back(vs[i], cs[i]);
graph[vs[i]].emplace_back(us[i], cs[i]);
}
function<int (int)> test = [&graph, &rs, n](int s) {
vector<vector<int>> waiting(n);
vector<bool> found(n), marc(n);
queue<int> q;
q.push(s);
int sz = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
++sz;
if (!found[rs[u]]) {
found[rs[u]] = true;
for (int x: waiting[rs[u]]) if (!marc[x]) {
marc[x] = true;
q.push(x);
}
}
for (auto [v, k]: graph[u]) if (!marc[v])
if (found[k]) {
marc[v] = true;
q.push(v);
}
else waiting[k].push_back(v);
}
return sz;
};
vector<int> best{}; int val = 1e9;
for (int i = 0; i < n; ++i) {
int x = test(i);
if (x < val) {
best = vector<int>{i};
val = x;
}
else if (x == val) best.push_back(i);
}
vector<int> ans(n);
for (int x: best)
ans[x] = 1;
return ans;
}
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... |