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;
using ll = long long;
vector<int> find_reachable(vector<int> R, vector<int> U, vector<int> V, vector<int> C) {
int N = R.size(), M = C.size();
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < M; i++) {
adj[U[i]].emplace_back(V[i], C[i]);
adj[V[i]].emplace_back(U[i], C[i]);
}
vector<int> p(N);
for (int i = 0; i < N; i++) {
vector<bool> have(N), vis(N);
vector<vector<int>> w(N);
queue<int> q;
vis[i] = 1;
q.push(i);
while (!q.empty()) {
int x = q.front();
q.pop();
p[i]++;
have[R[x]] = 1;
for (int y : w[R[x]]) {
if (!vis[y]) {
vis[y] = 1;
q.push(y);
}
}
w[R[x]].clear();
for (auto [y, z] : adj[x]) {
if (vis[y]) {
continue;
}
if (have[z]) {
vis[y] = 1;
q.push(y);
} else {
w[z].push_back(y);
}
}
}
}
int mn = *min_element(p.begin(), p.end());
vector<int> ans(N);
for (int i = 0; i < N; i++) {
if (p[i] == mn) {
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... |