結果
問題 | No.848 なかよし旅行 |
ユーザー |
|
提出日時 | 2020-04-25 23:56:59 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,289 bytes |
コンパイル時間 | 18,318 ms |
コンパイル使用メモリ | 377,208 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-11-08 02:45:15 |
合計ジャッジ時間 | 21,838 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | WA * 1 TLE * 1 -- * 24 |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:8:13 | 8 | let mut s = { | ----^ | | | help: remove this `mut` ... 107 | / input! { 108 | | n: usize, 109 | | m: usize, 110 | | p: usize1, ... | 113 | | edges: [(usize1, usize1, Cost); m], 114 | | } | |_____- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)
ソースコード
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}type Cost = u64;#[derive(Clone)]pub struct Edge {to: usize,cost: Cost,}type Graph = Vec<Vec<Edge>>;use std::cmp::Ordering;#[derive(PartialEq, Eq, PartialOrd)]struct State {at: usize,cost: Cost,}impl Ord for State {fn cmp(&self, other: &Self) -> Ordering {other.cost.cmp(&self.cost)}}use std::collections::BinaryHeap;const INF : Cost = std::u64::MAX;pub fn dijkstra(s: usize, g: &Graph) -> Vec<Cost> {let mut minc = vec![INF; g.len()];minc[s] = 0;let mut pq = BinaryHeap::new();pq.push(State { at: s, cost: 0 });while !pq.is_empty() {let cur = pq.pop().unwrap();if minc[cur.at] < cur.cost {continue;}for e in g[cur.at].iter() {let cost = cur.cost + e.cost;if minc[e.to] <= cost {continue;}minc[e.to] = cost;pq.push(State { at: e.to, cost });}}minc}fn main() {input! {n: usize,m: usize,p: usize1,q: usize1,t: Cost,edges: [(usize1, usize1, Cost); m],}let mut g = vec![vec![]; n];for (a, b, c) in edges {g[a].push(Edge { to: b, cost: c });g[b].push(Edge { to: a, cost: c });}let minc1 = dijkstra(0, &g);let mincp = dijkstra(p, &g);let mincq = dijkstra(q, &g);let mut ans : i64 = -1;let cost = minc1[p] + mincp[q] + mincq[0];if cost <= t {ans = std::cmp::max(ans, cost as i64);}let cost = minc1[q] + mincq[p] + mincp[0];if cost <= t {ans = std::cmp::max(ans, cost as i64);}for i in 0..n {for j in 0..n {let cost = minc1[i] + std::cmp::max(mincp[i] + mincp[j], mincq[i] + mincq[j]) + minc1[j];if cost > t {continue;}let score = minc1[i] + minc1[j] + t - cost;ans = std::cmp::max(ans, score as i64);}}println!("{}", ans);}