結果

問題 No.1473 おでぶなおばけさん
ユーザー iwotiwot
提出日時 2021-09-28 13:43:11
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 3,127 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 149,920 KB
実行使用メモリ 12,316 KB
最終ジャッジ日時 2023-09-22 02:54:14
合計ジャッジ時間 5,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 35 ms
5,788 KB
testcase_42 AC 34 ms
5,788 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 33 ms
8,792 KB
testcase_47 AC 41 ms
10,204 KB
testcase_48 AC 37 ms
10,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
          let mut s = String::new();
          std::io::stdin().read_line(&mut s).ok();
          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)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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() {
    use std::cmp::Ordering;

    #[derive(Clone, Eq, PartialEq, Debug)]
    struct Node {
        to: usize,
        max: u64,
    }

    impl PartialOrd for Node {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
            other.max.partial_cmp(&self.max)
        }
    }

    impl Ord for Node {
        fn cmp(&self, other: &Self) -> Ordering {
            other.max.cmp(&self.max)
        }
    }

    input!(n: usize, m: usize);
    let n = n + 1;
    let mut cities: Vec<Vec<Node>> = vec![vec![]; n];

    let mut input_d_max = 0;
    for _i in 0..m {
        input!(s: usize, t: usize, d: u64);
        if input_d_max < d {
            input_d_max = d;
        }
        cities[s].push(Node {
            to: t,
            max: d,
        });
        cities[t].push(Node {
            to: s,
            max: d,
        });
    }

    for i in 0..n {
        cities[i].sort_by(|a, b| b.max.partial_cmp(&a.max).unwrap() );
    }

    use std::collections::VecDeque;
    let mut que = VecDeque::new();
    que.push_front(1);
    let mut dist = vec![None; n];
    dist[1] = Some(0u64);
    let mut weight = 0;
    while !que.is_empty() {
        if let Some(this_index) = que.pop_front() {
            for i in 0..cities[this_index].len() {
                let to = cities[this_index][i].to;
                if dist[to].is_some() {
                    continue;
                }

                dist[to] = Some(dist[this_index].unwrap_or(0) + 1);
                que.push_front(to);
                if weight == 0 {
                    weight = cities[this_index][i].max;
                } else if weight > cities[this_index][i].max {
                    weight = cities[this_index][i].max;
                }
                break;
            }
        }
    }
    println!("{} {}", weight, dist[n-1].unwrap());
}

0