# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
434995 | | grt | Keys (IOI21_keys) | C++17 | | 2583 ms | 37428 KiB |
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>
#define ST first
#define ND second
#define PB push_back
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 300 * 1000 + 10, INF = 1e9;
vector<pi>ed[nax];
int n, m;
bool vis[nax];
bool done[nax];
int color[nax];
vector<pi>V[nax];
queue<int>Q;
int cnt[nax];
void dfs(int x) {
vis[x] = true;
Q.push(color[x]);
for(auto nbh : V[x]) if(!vis[nbh.ST] && done[nbh.ND]) {
dfs(nbh.ST);
}
}
vi find_reachable(vi r, vi u, vi v, vi c) {
n = (int)r.size();
m = (int)u.size();
for(int i = 0; i < n; ++i) {
color[i] = r[i];
}
for(int i = 0; i < m; ++i) {
ed[c[i]].emplace_back(u[i], v[i]);
V[u[i]].emplace_back(v[i], c[i]);
V[v[i]].emplace_back(u[i], c[i]);
}
int mi = INF;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
done[j] = vis[j] = false;
}
vis[i] = true;
Q.push(r[i]);
while(!Q.empty()) {
int x = Q.front();
Q.pop();
if(done[x]) continue;
done[x] = true;
for(auto [a,b] : ed[x]) {
if(vis[a] && !vis[b]) {
dfs(b);
} else if(!vis[a] && vis[b]) {
dfs(a);
}
}
}
for(int j = 0; j < n; ++j) cnt[i] += vis[j];
mi = min(mi, cnt[i]);
}
vi ans(n);
for(int i = 0; i < n; ++i) {
if(cnt[i] == mi) {
ans[i] = true;
} else {
ans[i] = false;
}
}
return ans;
}
//int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//vi w = find_reachable({0, 1, 1, 2},{0, 0, 1, 1, 3}, {1, 2, 2, 3, 1}, {0, 0, 1, 0, 2});
//vi w = find_reachable({0, 1, 1, 2, 2, 1, 2},{0, 0, 1, 1, 2, 3, 3, 4, 4, 5},
//{1, 2, 2, 3, 3, 4, 5, 5, 6, 6},
//{0, 0, 1, 0, 0, 1, 2, 0, 2, 1});
//vi w = find_reachable({0, 0, 0}, {0}, {1}, {0});
//for(int x : w) {
//cout << x << " ";
//}
//}
# | 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... |