aizu_online_judge/grl/
grl_5_b.rs1use competitive::prelude::*;
2#[doc(no_inline)]
3pub use competitive::{algebra::MaxOperation, graph::TreeGraphScanner, tree::ReRooting};
4
5#[verify::aizu_online_judge("GRL_5_B")]
6pub fn grl_5_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, n, (graph, w): @TreeGraphScanner::<usize, u64>::new(n));
10 let re = ReRooting::<MaxOperation<u64>, _>::new(&graph, |d, _vid, eid_opt| {
11 d + eid_opt.map_or(0, |eid| w[eid])
12 });
13 iter_print!(writer, @sep '\n', @it re.dp);
14}