aizu_online_judge/grl/
grl_1_a.rs

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