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;
struct dsu {
int n;
vector<int> p, s;
dsu(int n) : n(n), p(n), s(n, 1) {
iota(p.begin(), p.end(), 0);
}
int find(int x) {
return x == p[x] ? x : p[x] = find(p[x]);
}
int size(int x) {
return s[find(x)];
}
bool same(int x, int y) {
return find(x) == find(y);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return 0;
}
if (s[x] > s[y]) {
swap(x, y);
}
p[x] = y;
s[y] += s[x];
return 1;
}
};
vector<int> find_reachable(vector<int> R, vector<int> U, vector<int> V, vector<int> C) {
int N = R.size(), M = C.size();
if (C == vector(M, 0)) {
dsu uf(N);
for (int i = 0; i < M; i++) {
uf.unite(U[i], V[i]);
}
vector<int> p(N);
for (int i = 0; i < N; i++) {
if (R[i] == 0) {
p[i] = uf.size(i);
} else {
p[i] = 1;
}
}
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;
}
}
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:58:1: warning: control reaches end of non-void function [-Wreturn-type]
58 | }
| ^
# | 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... |