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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ld eps = 1e-8;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9 + 7;
#include "keys.h"
vector<set<int>> g;
vector<int> num;
int cnt = 0;
void dfs(int v, int number) {
num[v] = number;
cnt++;
for (auto u : g[v]) {
if (num[u] == -1) {
dfs(u, number);
}
}
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
ll n = r.size();
int m = u.size();
vector<int> res(n);
bool nonzer = 0;
for (int i = 0; i < n; i++) {
if (r[i] != 0)
nonzer = 1;
}
g.resize(n);
for (int i = 0; i < m; i++) {
g[u[i]].insert(v[i]);
g[v[i]].insert(u[i]);
}
num.resize(n, -1);
vector<int> sz;
int mini = n + 1;
for (int i = 0; i < n; i++) {
if (num[i] == -1) {
cnt = 0;
dfs(i, sz.size());
sz.push_back(cnt);
mini = min(mini, cnt);
}
}
for (int i = 0; i < n; i++) {
if (nonzer) {
if (r[i] != 0 || sz[num[i]] == 1) {
res[i] = 1;
}
} else {
if (sz[num[i]] == mini) {
res[i] = 1;
}
}
}
return res;
}
# | 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... |