aizu_online_judge/grl/
grl_1_a.rs

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