結果

問題 No.2739 Time is money
ユーザー t33ft33f
提出日時 2024-04-21 11:08:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 167,296 KB
実行使用メモリ 33,664 KB
最終ジャッジ日時 2024-04-21 11:09:00
合計ジャッジ時間 4,999 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 88 ms
20,352 KB
testcase_03 AC 116 ms
25,344 KB
testcase_04 AC 50 ms
19,712 KB
testcase_05 AC 67 ms
18,432 KB
testcase_06 AC 86 ms
23,040 KB
testcase_07 AC 144 ms
33,664 KB
testcase_08 AC 158 ms
33,152 KB
testcase_09 AC 166 ms
32,640 KB
testcase_10 AC 90 ms
32,896 KB
testcase_11 AC 144 ms
32,896 KB
testcase_12 AC 133 ms
33,408 KB
testcase_13 AC 101 ms
33,408 KB
testcase_14 AC 92 ms
32,640 KB
testcase_15 AC 66 ms
25,344 KB
testcase_16 AC 68 ms
25,216 KB
testcase_17 AC 147 ms
31,232 KB
testcase_18 AC 141 ms
32,256 KB
testcase_19 AC 72 ms
25,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
use std::collections::BinaryHeap;
use proconio::{input};

fn main() {
    input!{
        n: usize, m: usize, x: u64,
        es: [(usize, usize, u64, u64); m]
    }
    let mut adj = vec![Vec::new(); n];
    for (u, v, c, t) in es {
        adj[u - 1].push((v - 1, c + t * x));
        adj[v - 1].push((u - 1, c + t * x));
    }
    let mut dist = vec![u64::MAX; n];
    dist[0] = 0;
    let mut pq = BinaryHeap::new();
    pq.push((0, 0));
    while let Some((d, u)) = pq.pop() {
        if (-d) as u64 > dist[u] { continue; }
        for (v, c) in &adj[u] {
            let d1 = (-d) as u64 + c;
            if d1 < dist[*v] {
                dist[*v] = d1;
                pq.push((-(d1 as i64), *v));
            }
        }
    }

    if dist[n - 1] == u64::MAX {
        println!("-1");
    } else {
        println!("{}", (dist[n - 1] + x - 1) / x);
    }
}
0