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 <unordered_set>
using namespace std;
int solve(vector<int> r, vector<int> u, vector<int> v, vector<int> c, int s) {
unordered_set<int> vis;
unordered_set<int> keys;
vis.insert(s);
keys.insert(r[s]);
int added = 1;
int m = u.size();
while (added) {
added = 0;
for (int i = 0; i < m; i++) {
if (vis.find(u[i]) != vis.end()) {
if (vis.find(v[i]) == vis.end()) {
if (keys.find(c[i]) != keys.end()) {
added++;
vis.insert(v[i]);
keys.insert(r[v[i]]);
}
}
}
}
for (int i = 0; i < m; i++) {
if (vis.find(v[i]) != vis.end()) {
if (vis.find(u[i]) == vis.end()) {
if (keys.find(c[i]) != keys.end()) {
added++;
vis.insert(u[i]);
keys.insert(r[u[i]]);
}
}
}
}
}
return vis.size();
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n = r.size();
vector<int> canreach(n);
for (int i = 0; i < n; i++) {
canreach[i] = solve(r, u, v, c, i);
// printf("%d\n", canreach[i]);
}
int least = canreach[0];
for (int i = 1; i < n; i++) least = min(least, canreach[i]);
vector<int> ans(n, 0);
for (int i = 0; i < n; i++) if (canreach[i] == least) ans[i] = 1;
return ans;
}
# | 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... |