結果

問題 No.1473 おでぶなおばけさん
ユーザー taotao54321taotao54321
提出日時 2021-04-15 03:34:48
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,693 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 150,316 KB
実行使用メモリ 17,096 KB
最終ジャッジ日時 2023-09-13 17:29:56
合計ジャッジ時間 51,123 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 TLE -
testcase_03 WA -
testcase_04 AC 1,210 ms
9,932 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 24 ms
8,380 KB
testcase_11 WA -
testcase_12 AC 26 ms
9,152 KB
testcase_13 AC 10 ms
6,008 KB
testcase_14 AC 8 ms
4,952 KB
testcase_15 AC 13 ms
8,684 KB
testcase_16 AC 22 ms
7,756 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 709 ms
10,484 KB
testcase_22 AC 1,681 ms
12,708 KB
testcase_23 AC 1,681 ms
11,040 KB
testcase_24 AC 1,405 ms
11,456 KB
testcase_25 AC 1,567 ms
12,444 KB
testcase_26 AC 1,491 ms
14,512 KB
testcase_27 AC 240 ms
5,796 KB
testcase_28 TLE -
testcase_29 AC 994 ms
10,752 KB
testcase_30 AC 1,125 ms
13,940 KB
testcase_31 TLE -
testcase_32 WA -
testcase_33 AC 1,421 ms
11,612 KB
testcase_34 AC 739 ms
7,008 KB
testcase_35 AC 546 ms
7,112 KB
testcase_36 AC 609 ms
9,436 KB
testcase_37 AC 1,551 ms
11,648 KB
testcase_38 AC 164 ms
4,380 KB
testcase_39 AC 23 ms
7,800 KB
testcase_40 AC 23 ms
7,792 KB
testcase_41 AC 11 ms
7,304 KB
testcase_42 AC 11 ms
7,308 KB
testcase_43 AC 1,138 ms
12,656 KB
testcase_44 AC 1,148 ms
12,716 KB
testcase_45 AC 1,138 ms
12,696 KB
testcase_46 AC 1,308 ms
10,216 KB
testcase_47 AC 1,584 ms
11,796 KB
testcase_48 AC 1,579 ms
11,520 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;
        }
        dbg!((s, w, k));

        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));
        graph[t].push((s, d));
    }

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

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