結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 132 ms
18,872 KB
testcase_03 AC 74 ms
14,736 KB
testcase_04 AC 77 ms
11,040 KB
testcase_05 AC 30 ms
4,924 KB
testcase_06 AC 129 ms
15,036 KB
testcase_07 AC 114 ms
19,508 KB
testcase_08 AC 208 ms
19,480 KB
testcase_09 AC 100 ms
19,424 KB
testcase_10 AC 25 ms
10,588 KB
testcase_11 AC 28 ms
12,136 KB
testcase_12 AC 26 ms
11,480 KB
testcase_13 AC 16 ms
7,608 KB
testcase_14 AC 12 ms
6,296 KB
testcase_15 AC 24 ms
10,884 KB
testcase_16 AC 23 ms
9,812 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 35 ms
10,112 KB
testcase_20 AC 55 ms
13,532 KB
testcase_21 AC 60 ms
12,476 KB
testcase_22 AC 43 ms
14,640 KB
testcase_23 AC 39 ms
12,888 KB
testcase_24 AC 35 ms
13,008 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 160 ms
18,964 KB
testcase_29 AC 65 ms
12,556 KB
testcase_30 AC 95 ms
15,796 KB
testcase_31 AC 97 ms
16,980 KB
testcase_32 AC 72 ms
15,372 KB
testcase_33 AC 55 ms
13,200 KB
testcase_34 AC 33 ms
7,808 KB
testcase_35 AC 25 ms
7,860 KB
testcase_36 AC 49 ms
10,948 KB
testcase_37 AC 96 ms
13,248 KB
testcase_38 AC 11 ms
4,376 KB
testcase_39 AC 24 ms
10,036 KB
testcase_40 AC 24 ms
10,100 KB
testcase_41 AC 23 ms
9,680 KB
testcase_42 AC 23 ms
9,664 KB
testcase_43 AC 34 ms
13,724 KB
testcase_44 AC 34 ms
13,768 KB
testcase_45 AC 33 ms
13,724 KB
testcase_46 AC 54 ms
12,048 KB
testcase_47 AC 72 ms
13,996 KB
testcase_48 AC 79 ms
13,532 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 = 2000_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