이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |