結果
問題 | No.788 トラックの移動 |
ユーザー |
|
提出日時 | 2022-12-05 23:42:24 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,919 bytes |
コンパイル時間 | 26,481 ms |
コンパイル使用メモリ | 400,824 KB |
実行使用メモリ | 33,408 KB |
最終ジャッジ日時 | 2024-10-12 19:51:59 |
合計ジャッジ時間 | 19,232 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 2 |
ソースコード
use std::{cmp::Reverse, collections::BinaryHeap}; const INF: usize = 1usize << 60; fn dijkstra(start: usize, paths: &Vec<Vec<(usize, usize)>>) -> Vec<usize> { let mut costs = vec![INF; paths.len()]; let mut que = BinaryHeap::new(); que.push(Reverse((0, start))); costs[start] = 0; while let Some(Reverse((cost, dest))) = que.pop() { if cost > costs[dest] { continue; } for &(v, ncost) in paths[dest].iter() { if costs[dest] + ncost < costs[v] { costs[v] = costs[dest] + ncost; que.push(Reverse((costs[v], v))); } } } costs } fn main() { let mut nml = String::new(); std::io::stdin().read_line(&mut nml).ok(); let nml: Vec<usize> = nml.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nml[0]; let m = nml[1]; let l = nml[2] - 1; let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: Vec<usize> = t.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut paths = vec![vec![]; n]; for _ in 0..m { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a= temp[0]-1; let b= temp[1]-1; let c= temp[2]; paths[a].push((b, c)); paths[b].push((a, c)); } let mut result = INF; let mut mapping = Vec::with_capacity(n); for i in 0..n { mapping.push(dijkstra(i, &paths)); } for i in 0..n { let moving = (0..n).filter(|&j| t[j] > 0).map(|j| mapping[i][l] + 2*mapping[i][j] - mapping[j][l] - mapping[i][j]).max().unwrap(); let total = (0..n).map(|j| t[j] * mapping[i][j]).sum::<usize>() * 2 + mapping[i][l] - moving; result = result.min(total); } println!("{}", result); }