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;
using idata = vector<int>;
using igrid = vector<idata>;
using t_road = pair<int, int>;
using t_roads = vector<t_road>;
using t_graph = vector<t_roads>;
using bdata = vector<bool>;
int N, M;
t_graph roads;
t_graph roads_by_key;
idata key_type;
int compute (int node) {
bdata keys_found(N);
bdata node_visit(N);
queue<int> nodes;
int size = 0;
nodes.push(node); node_visit[node] = true;
while (nodes.size() != 0) {
size ++;
int curr = nodes.front(); nodes.pop();
for (const auto &road : roads[curr]) {
int type = road.second; int next = road.first;
if (!keys_found[type]) continue ;
if (node_visit[next]) continue ;
node_visit[next] = true;
nodes.push(next);
}
if (keys_found[key_type[curr]]) continue ;
keys_found[key_type[curr]] = true;
for (const auto &road : roads_by_key[key_type[curr]]) {
int a = road.first; int b = road.second;
if (!(node_visit[a] ^ node_visit[b])) continue ;
int next = node_visit[a] ? b : a;
node_visit[next] = true;
nodes.push(next);
}
}
return size;
}
idata find_reachable(idata r, idata u, idata v, idata c) {
N = r.size();
M = u.size();
key_type = r;
roads.resize(N);
roads_by_key.resize(N);
for (int i = 0; i < M; i ++) {
roads[u[i]].push_back({ v[i], c[i] });
roads[v[i]].push_back({ u[i], c[i] });
roads_by_key[c[i]].push_back({ u[i], v[i] });
}
idata ans(N);
for (int i = 0; i < N; i ++) ans[i] = compute(i);
int mn = 1e9;
for (int u : ans) mn = min(mn, u);
for (int i = 0; i < N; i ++)
ans[i] = ans[i] == mn;
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... |