# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
1172195 | | gyg | Keys (IOI21_keys) | C++20 | | 3096 ms | 31812 KiB |
#include "keys.h"
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define arr array
#define pii pair<int, int>
#define fir first
#define sec second
const int N = 3e5 + 5;
// Zero indexing
int n;
arr<int, N> cl;
arr<vec<pii>, N> adj;
arr<bool, N> ngh_vs;
void ngh_dfs(int u, int src) {
ngh_vs[u] = true;
for (pii x : adj[u]) {
if (x.sec != cl[src]) continue;
if (ngh_vs[x.fir]) continue;
ngh_dfs(x.fir, src);
}
}
arr<vec<int>, N> ngh;
void ngh_cmp() {
for (int u = 0; u < n; u++) {
ngh_vs.fill(false);
ngh_dfs(u, u);
for (int v = 0; v < n; v++)
if (ngh_vs[v]) ngh[u].push_back(v);
}
// for (int u = 0; u < n; u++) {
// cout << u << ": ";
// for (int v : ngh[u]) cout << v << " ";
// cout << '\n';
// }
}
arr<bool, N> cnt_vs;
void cnt_dfs(int u) {
cnt_vs[u] = true;
for (int v : ngh[u])
if (!cnt_vs[v]) cnt_dfs(v);
}
arr<int, N> cnt;
void cnt_cmp() {
for (int u = 0; u < n; u++) {
cnt_vs.fill(false);
cnt_dfs(u);
cnt[u] = accumulate(cnt_vs.begin(), cnt_vs.begin() + n, 0);
}
}
vec<int> find_reachable(vec<int> _cl, vec<int> _u, vec<int> _v, vec<int> _c) {
n = _cl.size();
for (int u = 0; u < n; u++) cl[u] = _cl[u];
for (int i = 0; i < _u.size(); i++) {
int u = _u[i], v = _v[i], c = _c[i];
adj[u].push_back({v, c});
adj[v].push_back({u, c});
}
ngh_cmp();
cnt_cmp();
vec<int> ans(n);
int mn = *min_element(cnt.begin(), cnt.begin() + n);
for (int u = 0; u < n; u++)
if (cnt[u] == mn) ans[u] = 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... |