結果

問題 No.1473 おでぶなおばけさん
ユーザー StrorkisStrorkis
提出日時 2021-04-09 22:28:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 146,868 KB
実行使用メモリ 16,800 KB
最終ジャッジ日時 2023-09-07 11:56:48
合計ジャッジ時間 8,000 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 139 ms
16,180 KB
testcase_03 AC 67 ms
12,484 KB
testcase_04 AC 77 ms
9,496 KB
testcase_05 AC 29 ms
4,412 KB
testcase_06 AC 126 ms
12,624 KB
testcase_07 AC 124 ms
16,800 KB
testcase_08 AC 187 ms
16,644 KB
testcase_09 AC 97 ms
16,760 KB
testcase_10 AC 20 ms
8,320 KB
testcase_11 AC 22 ms
9,780 KB
testcase_12 AC 20 ms
9,084 KB
testcase_13 AC 12 ms
5,964 KB
testcase_14 AC 9 ms
4,880 KB
testcase_15 AC 19 ms
8,620 KB
testcase_16 AC 18 ms
7,484 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 30 ms
8,396 KB
testcase_20 AC 53 ms
11,560 KB
testcase_21 AC 59 ms
10,156 KB
testcase_22 AC 52 ms
12,372 KB
testcase_23 AC 44 ms
10,980 KB
testcase_24 AC 39 ms
11,136 KB
testcase_25 AC 96 ms
11,992 KB
testcase_26 AC 115 ms
14,028 KB
testcase_27 AC 21 ms
5,824 KB
testcase_28 AC 158 ms
16,584 KB
testcase_29 AC 55 ms
10,248 KB
testcase_30 AC 86 ms
13,272 KB
testcase_31 AC 89 ms
14,172 KB
testcase_32 AC 82 ms
12,932 KB
testcase_33 AC 58 ms
10,940 KB
testcase_34 AC 32 ms
6,708 KB
testcase_35 AC 25 ms
6,684 KB
testcase_36 AC 47 ms
9,220 KB
testcase_37 AC 108 ms
11,452 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 18 ms
7,736 KB
testcase_40 AC 19 ms
7,752 KB
testcase_41 AC 17 ms
7,252 KB
testcase_42 AC 18 ms
7,292 KB
testcase_43 AC 34 ms
12,164 KB
testcase_44 AC 31 ms
12,076 KB
testcase_45 AC 30 ms
12,148 KB
testcase_46 AC 46 ms
10,172 KB
testcase_47 AC 89 ms
11,624 KB
testcase_48 AC 76 ms
11,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::BinaryHeap;
use std::cmp::Reverse;

const INF: u32 = 1 << 30;

fn run<'a, I: Iterator<Item = &'a str>>(mut scanner: I) {
    macro_rules! scan {
        ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
        (($($t:tt),*)) => (($(scan!($t)),*));
        ([$($t:tt),*]) => ([$(scan!($t)),*]);
        (Usize1) => (scan!(usize) - 1);
        (Bytes) => (scan!(String).into_bytes());
        ($t:ty) => (scanner.next().unwrap().parse::<$t>().unwrap());
    }
    macro_rules! input {
        ($($($v:ident)* : $t:tt),* $(,)?) => ($(let $($v)* = scan!($t);)*);
    }
    
    input! {
        n: usize, m: usize,
    }

    let mut g = vec![vec![]; n];
    for _ in 0..m {
        input! {
            s: Usize1, t: Usize1, d: u32,
        }

        g[s].push((t, d));
        g[t].push((s, d));
    }

    let (mut l, mut r) = (0, INF);
    while r - l > 1 {
        let w = (l + r) / 2;

        let mut stack = Vec::new();
        stack.push(0);
        let mut used = vec![false; n];
        used[0] = true;
        while let Some(from) = stack.pop() {
            for &(to, d) in &g[from] {
                if w > d || used[to] { continue; }
                stack.push(to);
                used[to] = true;
            }
        }

        if *used.last().unwrap() {
            l = w;
        } else {
            r = w;
        }
    }

    let w = l;

    let mut dist = vec![INF; n];
    let mut heap = BinaryHeap::new();
    dist[0] = 0;
    heap.push((Reverse(0), 0));
    while let Some((Reverse(cost), from)) = heap.pop() {
        if dist[from] < cost { continue; }
        for &(to, d) in &g[from] {
            if w > d { continue; }
            let next_cost = cost + 1;
            if next_cost < dist[to] {
                dist[to] = next_cost;
                heap.push((Reverse(next_cost), to));
            }
        }
    }

    println!("{} {}", w, dist.last().unwrap());
}

fn main() {
    let ref mut buf = Vec::new();
    std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
    run(std::str::from_utf8(buf).unwrap().split_whitespace());
}
0