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 "keys.h"
#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 = r.size();
vector<vector<array<int, 2>>> G(n);
for (int i = 0; i < U.size(); i++) {
G[U[i]].push_back({V[i], C[i]});
G[V[i]].push_back({U[i], C[i]});
}
vector<int> ans, perm(n), vis(n, -1), visc(n, -1);
iota(perm.begin(), perm.end(), 0);
shuffle(perm.begin(), perm.end(), mt19937(time(0)));
queue<int> Q;
vector<bool> solved(n);
for (int x : perm) {
vector<int> V = {x};
Q.push(x), vis[x] = visc[r[x]] = x, solved[x] = 1;
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (auto &e : G[u]) if (vis[e[0]] != x && visc[e[1]] == x) {
V.push_back(e[0]);
if (solved[e[0]] || !ans.empty() && V.size() > ans.size()) goto nxt;
Q.push(e[0]), vis[e[0]] = visc[r[e[0]]] = x;
}
}
if (V.size() < ans.size()) ans = V;
else copy(V.begin(), V.end(), back_inserter(ans));
nxt:;
}
vector<int> res(n);
for (int x : ans) res[x] = 1;
return res;
}
Compilation message (stderr)
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int i = 0; i < U.size(); i++) {
| ~~^~~~~~~~~~
keys.cpp:24:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | if (solved[e[0]] || !ans.empty() && V.size() > ans.size()) goto nxt;
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |