結果

問題 No.1473 おでぶなおばけさん
ユーザー Ricky_ponRicky_pon
提出日時 2021-04-09 22:41:09
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,327 bytes
コンパイル時間 5,683 ms
コンパイル使用メモリ 146,952 KB
実行使用メモリ 19,468 KB
最終ジャッジ日時 2023-09-07 12:15:39
合計ジャッジ時間 10,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 93 ms
18,756 KB
testcase_03 AC 65 ms
14,720 KB
testcase_04 AC 70 ms
11,040 KB
testcase_05 AC 28 ms
4,932 KB
testcase_06 AC 107 ms
15,048 KB
testcase_07 AC 94 ms
19,468 KB
testcase_08 AC 140 ms
19,452 KB
testcase_09 AC 76 ms
19,428 KB
testcase_10 AC 22 ms
10,676 KB
testcase_11 AC 26 ms
12,132 KB
testcase_12 AC 25 ms
11,476 KB
testcase_13 AC 16 ms
7,576 KB
testcase_14 AC 12 ms
6,284 KB
testcase_15 AC 22 ms
10,784 KB
testcase_16 AC 21 ms
9,800 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 31 ms
10,220 KB
testcase_20 AC 48 ms
13,532 KB
testcase_21 AC 53 ms
12,484 KB
testcase_22 AC 36 ms
14,664 KB
testcase_23 AC 31 ms
12,904 KB
testcase_24 AC 29 ms
13,084 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 112 ms
19,008 KB
testcase_29 AC 61 ms
12,568 KB
testcase_30 AC 84 ms
15,968 KB
testcase_31 AC 83 ms
16,988 KB
testcase_32 AC 69 ms
15,428 KB
testcase_33 AC 52 ms
13,196 KB
testcase_34 AC 30 ms
7,836 KB
testcase_35 AC 24 ms
7,864 KB
testcase_36 AC 45 ms
10,952 KB
testcase_37 AC 79 ms
13,124 KB
testcase_38 AC 10 ms
4,376 KB
testcase_39 AC 24 ms
10,096 KB
testcase_40 AC 23 ms
10,052 KB
testcase_41 AC 23 ms
9,644 KB
testcase_42 AC 23 ms
9,672 KB
testcase_43 AC 34 ms
13,772 KB
testcase_44 AC 31 ms
13,788 KB
testcase_45 AC 31 ms
13,776 KB
testcase_46 AC 46 ms
12,108 KB
testcase_47 AC 58 ms
13,964 KB
testcase_48 AC 58 ms
13,500 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:7:13
   |
7  |           let mut s = {
   |               ----^
   |               |
   |               help: remove this `mut`
...
51 | /     input! {
52 | |         n: usize,
53 | |         m: usize,
54 | |         edges: [(usize, usize, i32); m]
55 | |     }
   | |_____- in this macro invocation
   |
   = note: `#[warn(unused_mut)]` on by default
   = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

ソースコード

diff #

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        edges: [(usize, usize, i32); m]
    }
    let mut gr = vec![vec![]; n];
    for i in 0..m {
        let (s, t, d) = edges[i];
        let s = s - 1;
        let t = t - 1;
        gr[s].push((t, d));
        gr[t].push((s, d));
    }

    let mut low = 0;
    let mut high = 1000_000_000;
    while high - low > 1 {
        let mid = (high + low) / 2;
        if bfs(&gr, mid) >= 0 {
            low = mid;
        } else {
            high = mid;
        }
    }
    println!("{} {}", low, bfs(&gr, low));
}

fn bfs(gr: &Vec<Vec<(usize, i32)>>, min_weight: i32) -> i32 {
    let n = gr.len();
    let mut d = vec![None; n];
    let mut que = std::collections::VecDeque::new();
    d[0] = Some(0);
    que.push_back(0);
    while !que.is_empty() {
        let v = que.pop_front().unwrap();
        for &(nv, c) in &gr[v] {
            if c >= min_weight && d[nv].is_none() {
                d[nv] = Some(d[v].unwrap() + 1);
                que.push_back(nv);
            }
        }
    }
    return if d[n - 1].is_none() {
        -1
    } else {
        d[n - 1].unwrap()
    };
}
0