aizu_online_judge/grl/
grl_1_b.rs

1#[doc(no_inline)]
2pub use competitive::graph::{DirectedGraphScanner, ShortestPathExt};
3use competitive::prelude::*;
4
5#[verify::aizu_online_judge("GRL_1_B")]
6pub fn grl_1_b(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, vs, es, r, (graph, d): @DirectedGraphScanner::<usize, i64>::new(vs, es));
10    let cost = graph
11        .option_sp_additive()
12        .bellman_ford([r], &|eid| Some(d[eid]), true);
13    if let Some(cost) = cost {
14        for u in graph.vertices() {
15            match cost[u] {
16                Some(d) => writeln!(writer, "{}", d).ok(),
17                None => writeln!(writer, "INF").ok(),
18            };
19        }
20    } else {
21        writeln!(writer, "NEGATIVE CYCLE").ok();
22    }
23}