aizu_online_judge/grl/
grl_1_a.rs1use competitive::prelude::*;
2use competitive::{
3 graph::{DirectedGraphScanner, ShortestPathExt},
4 num::Bounded,
5};
6
7#[verify::aizu_online_judge("GRL_1_A")]
8pub fn grl_1_a(reader: impl Read, writer: impl Write) {
9 prepare_io!(reader, writer);
10 sc!(vs, es, r, (graph, d): @DirectedGraphScanner::<usize, u64>::new(vs, es));
11 let cost = graph.standard_sp_additive().dijkstra([r], |eid| d[eid]);
12 for u in graph.vertices() {
13 if cost[u].is_maximum() {
14 pp!("INF");
15 } else {
16 pp!(cost[u]);
17 }
18 }
19}
20
21#[verify::aizu_online_judge("GRL_1_A")]
22pub fn grl_1_a_option(reader: impl Read, writer: impl Write) {
23 prepare_io!(reader, writer);
24 sc!(vs, es, r, (graph, d): @DirectedGraphScanner::<usize, u64>::new(vs, es));
25 let cost = graph.option_sp_additive().dijkstra([r], |eid| Some(d[eid]));
26 for u in graph.vertices() {
27 match cost[u] {
28 Some(d) => pp!(d),
29 None => pp!("INF"),
30 };
31 }
32}