# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
437690 | SHZhang | Keys (IOI21_keys) | C++17 | 146 ms | 17220 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 <vector>
#include <queue>
#include <algorithm>
using namespace std;
int n, m;
vector<pair<int, int> > graph[2005];
vector<pair<int, int> > key[2005];
bool haskey[2005];
bool access[2005];
int p[2005];
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
vector<int> ans(r.size(), 1);
n = r.size(); m = u.size();
int minp = n + 1;
for (int i = 0; i < m; i++) {
graph[u[i]].push_back(make_pair(v[i], c[i]));
graph[v[i]].push_back(make_pair(u[i], c[i]));
key[c[i]].push_back(make_pair(u[i], v[i]));
}
for (int x = 0; x < n; x++) {
for (int j = 0; j < n; j++) haskey[j] = access[j] = false;
access[x] = true;
queue<int> que; que.push(x);
while (!que.empty()) {
int node = que.front(); que.pop();
p[x]++;
if (!haskey[r[node]]) {
haskey[r[node]] = true;
for (int i = 0; i < key[r[node]].size(); i++) {
pair<int, int> edge = key[r[node]][i];
if (access[edge.first] && !access[edge.second]) {
access[edge.second] = true;
que.push(edge.second);
}
if (!access[edge.first] && access[edge.second]) {
access[edge.first] = true;
que.push(edge.first);
}
}
}
for (int i = 0; i < graph[node].size(); i++) {
pair<int, int> edge = graph[node][i];
if (haskey[edge.second] && !access[edge.first]) {
access[edge.first] = true;
que.push(edge.first);
}
}
}
minp = min(minp, p[x]);
}
for (int i = 0; i < n; i++) {
ans[i] = (p[i] == minp ? 1 : 0);
}
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... |