結果

問題 No.1473 おでぶなおばけさん
ユーザー taotao54321taotao54321
提出日時 2021-04-15 04:10:17
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,914 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 150,748 KB
実行使用メモリ 16,684 KB
最終ジャッジ日時 2023-09-13 18:15:12
合計ジャッジ時間 6,510 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 108 ms
16,056 KB
testcase_03 AC 57 ms
12,352 KB
testcase_04 AC 60 ms
9,668 KB
testcase_05 AC 24 ms
4,444 KB
testcase_06 AC 100 ms
12,472 KB
testcase_07 AC 91 ms
16,672 KB
testcase_08 AC 145 ms
16,684 KB
testcase_09 AC 74 ms
16,660 KB
testcase_10 AC 17 ms
8,256 KB
testcase_11 AC 19 ms
9,716 KB
testcase_12 AC 17 ms
9,188 KB
testcase_13 AC 10 ms
6,044 KB
testcase_14 AC 8 ms
4,976 KB
testcase_15 AC 16 ms
8,720 KB
testcase_16 AC 15 ms
7,520 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 26 ms
8,432 KB
testcase_20 AC 43 ms
11,464 KB
testcase_21 AC 51 ms
10,120 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 135 ms
12,064 KB
testcase_26 AC 143 ms
14,148 KB
testcase_27 AC 28 ms
5,812 KB
testcase_28 AC 126 ms
16,540 KB
testcase_29 AC 51 ms
10,460 KB
testcase_30 AC 76 ms
13,440 KB
testcase_31 AC 64 ms
14,204 KB
testcase_32 AC 63 ms
12,776 KB
testcase_33 AC 45 ms
11,040 KB
testcase_34 AC 25 ms
6,732 KB
testcase_35 AC 18 ms
6,692 KB
testcase_36 AC 44 ms
9,136 KB
testcase_37 AC 74 ms
11,332 KB
testcase_38 AC 10 ms
4,376 KB
testcase_39 AC 16 ms
7,680 KB
testcase_40 AC 15 ms
7,772 KB
testcase_41 AC 16 ms
7,312 KB
testcase_42 AC 16 ms
7,320 KB
testcase_43 AC 22 ms
11,248 KB
testcase_44 AC 22 ms
11,212 KB
testcase_45 AC 22 ms
11,208 KB
testcase_46 AC 41 ms
10,248 KB
testcase_47 AC 52 ms
11,568 KB
testcase_48 AC 59 ms
11,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(clippy::many_single_char_names)]

use std::collections::VecDeque;
use std::io::Read as _;

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

fn solve(n: usize, graph: &[Vec<(usize, u32)>]) -> (u32, u32) {
    const W_MAX: u32 = 10_u32.pow(9) + 1;

    let mut ans_k = 0;

    let mut lo = 1;
    let mut hi = W_MAX;
    while lo + 1 < hi {
        let mid = (lo + hi) / 2;
        if let Some(k) = try_bfs(n, graph, mid) {
            ans_k = k;
            lo = mid;
        } else {
            hi = mid;
        }
    }

    (lo, ans_k)
}

fn try_bfs(n: usize, graph: &[Vec<(usize, u32)>], w: u32) -> Option<u32> {
    const INF: u32 = u32::MAX;

    let mut ks = vec![INF; n];
    let mut que = VecDeque::new();
    ks[0] = 0;
    que.push_back(0);

    while !que.is_empty() {
        let s = que.pop_front().unwrap();

        let k_new = ks[s] + 1;
        for &(t, d) in &graph[s] {
            if d < w {
                continue;
            }
            if chmin!(ks[t], k_new) {
                que.push_back(t);
            }
        }
    }

    let res = ks[n - 1];
    (res != INF).then(|| res)
}

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