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> get(vector<int> p) {
int mn = *min_element(p.begin(), p.end());
vector<int> ans(p.size());
for (int i = 0; i < p.size(); i++) {
ans[i] = p[i] == mn;
}
return ans;
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
int n = r.size();
int 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]);
}
auto bfs = [&](int s) {
vector<bool> vis(n);
vector<bool> have(n);
vector<vector<int>> w(n);
queue<int> q;
vis[s] = 1;
q.push(s);
int ans = 0;
while (!q.empty()) {
int x = q.front();
q.pop();
ans++;
have[r[x]] = 1;
for (int v : w[r[x]]) {
if (!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
w[r[x]].clear();
for (auto [y, z] : adj[x]) {
if (have[z]) {
if (!vis[y]) {
vis[y] = 1;
q.push(y);
}
} else {
w[z].push_back(y);
}
}
}
return ans;
};
vector<vector<int>> dir(n);
vector<vector<int>> rev(n);
for (int x = 0; x < n; x++) {
for (auto [y, z] : adj[x]) {
if (r[x] == z) {
dir[x].push_back(y);
rev[y].push_back(x);
}
}
}
vector<bool> vis(n);
vector<int> s;
auto dfs1 = [&](auto dfs1, int x) -> void {
vis[x] = 1;
for (int y : dir[x]) {
if (!vis[y]) {
dfs1(dfs1, y);
}
}
s.push_back(x);
};
for (int i = 0; i < n; i++) {
if (!vis[i]) {
dfs1(dfs1, i);
}
}
vector<int> t;
auto dfs = [&](auto dfs, int x) -> void {
t.push_back(x);
vis[x] = 1;
for (int y : rev[x]) {
if (!vis[y]) {
dfs(dfs, y);
}
}
};
fill(vis.begin(), vis.end(), 0);
vector<int> p(n, n + 1);
vector<vector<int>> cand;
for (int i = n - 1; i >= 0; i--) {
if (!vis[s[i]]) {
t.clear();
dfs(dfs, s[i]);
bool flag = 0;
for (int x : t) {
for (int y : dir[x]) {
if (!vis[y]) {
flag = 1;
}
}
}
if (flag) {
continue;
}
cand.push_back(t);
}
}
return get(p);
}
Compilation message (stderr)
keys.cpp: In function 'std::vector<int> get(std::vector<int>)':
keys.cpp:7:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:20:7: warning: variable 'bfs' set but not used [-Wunused-but-set-variable]
20 | auto bfs = [&](int s) {
| ^~~
# | 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... |