use std::io::Read; fn dfs(v: usize, cost: u32, graph: &Vec>, ans: &mut Vec) { if graph[v].len() == 0 { ans[v] += cost; return; } for &(nv, nc) in graph[v].iter() { dfs(nv, cost * nc, graph, ans); } } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let m: usize = itr.next().unwrap().parse().unwrap(); let mut graph: Vec> = vec![Vec::new(); n]; for _ in 0..m { let p: usize = itr.next().unwrap().parse::().unwrap() - 1; let q: u32 = itr.next().unwrap().parse().unwrap(); let r: usize = itr.next().unwrap().parse::().unwrap() - 1; graph[r].push((p, q)); } let mut ans: Vec = vec![0; n]; dfs(n - 1, 1, &graph, &mut ans); for i in 0..n - 1 { println!("{}", ans[i]); } }