結果

問題 No.1473 おでぶなおばけさん
ユーザー taotao54321taotao54321
提出日時 2021-04-15 03:24:30
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 4,976 ms
コンパイル使用メモリ 139,292 KB
実行使用メモリ 14,148 KB
最終ジャッジ日時 2023-09-13 17:16:37
合計ジャッジ時間 8,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
4,632 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 9 ms
4,640 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 9 ms
5,768 KB
testcase_42 AC 9 ms
5,756 KB
testcase_43 AC 20 ms
11,156 KB
testcase_44 AC 20 ms
11,184 KB
testcase_45 AC 21 ms
11,252 KB
testcase_46 AC 21 ms
10,252 KB
testcase_47 AC 28 ms
11,500 KB
testcase_48 AC 24 ms
11,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(clippy::many_single_char_names)]

use std::cmp::Reverse;
use std::collections::BinaryHeap;
use std::io::Read as _;

macro_rules! chmax {
    ($xmax:expr, $x:expr) => {{
        if $xmax < $x {
            $xmax = $x;
            true
        } else {
            false
        }
    }};
}

fn solve(n: usize, graph: &[Vec<(usize, u32)>]) -> (u32, u32) {
    let mut bests = vec![(0, Reverse(u32::MAX)); n];
    let mut que = BinaryHeap::new();
    bests[0] = (u32::MAX, Reverse(0));
    que.push((u32::MAX, Reverse(0), 0));

    while !que.is_empty() {
        let (w, Reverse(k), s) = que.pop().unwrap();
        if (w, Reverse(k)) < bests[s] {
            continue;
        }

        for &(t, d) in &graph[s] {
            let w_new = w.min(d);
            let k_new = k + 1;
            if chmax!(bests[t], (w_new, Reverse(k_new))) {
                que.push((w_new, Reverse(k_new), t));
            }
        }
    }

    let (ans_w, Reverse(ans_k)) = bests[n - 1];
    (ans_w, ans_k)
}

fn main() {
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();

    let mut tokens = input.split_ascii_whitespace();
    macro_rules! read {
        ($ty:ty) => {{
            tokens.next().unwrap().parse::<$ty>().unwrap()
        }};
    }

    let n = read!(usize);
    let m = read!(usize);

    let mut graph: Vec<Vec<(usize, u32)>> = vec![vec![]; n];
    for _ in 0..m {
        let s = read!(usize) - 1;
        let t = read!(usize) - 1;
        let d = read!(u32);
        graph[s].push((t, d));
    }

    let (ans_w, ans_k) = solve(n, &graph);

    println!("{} {}", ans_w, ans_k);
}
0