// -*- coding:utf-8-unix -*- use std::cmp::Ordering; use proconio::input; use std::collections::BinaryHeap; #[derive(Debug)] struct Edge { to: usize, length: i64 } #[derive(Debug)] struct Entry { to: usize, length: i64 } impl PartialEq for Entry { fn eq(&self, other: &Self) -> bool { self.length == other.length } } impl Eq for Entry {} impl PartialOrd for Entry { fn partial_cmp(&self, other: &Self) -> Option { other.length.partial_cmp(&self.length) } } impl Ord for Entry { fn cmp(&self, other: &Self) -> Ordering { self.length.cmp(&other.length) } } fn main() { input! { n: usize, m: usize, } let mut da: Vec> = Vec::new(); for _ in 0..n * 2 { da.push(Vec::new()); } for _ in 0..m { input! { a: usize, b: usize, c: i64, x: i32, } da[n + a - 1].push(Edge { to: n + b - 1, length: c }); da[n + b - 1].push(Edge { to: n + a - 1, length: c }); if x == 1 { da[n + a - 1].push(Edge { to: b - 1, length: c }); da[n + b - 1].push(Edge { to: a - 1, length: c }); } else { da[a - 1].push(Edge { to: b - 1, length: c }); da[b - 1].push(Edge { to: a - 1, length: c }); } } let mut used = Vec::new(); used.resize(n*2, -1); let mut pq = BinaryHeap::new(); pq.push(Entry{ to: n*2-1, length: 0}); loop { let now = pq.pop(); match now { None => break, Some(x) => { if used[x.to] < 0 { used[x.to] = x.length; for to in &da[x.to] { pq.push(Entry {to: to.to, length: x.length + to.length }); } } } } } for i in 0..n-1 { println!("{}", used[i]); } }