結果

問題 No.2712 Play more!
ユーザー Yukino DX.Yukino DX.
提出日時 2024-03-31 15:25:11
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,484 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 184,600 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:25:14
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 15 ms
6,676 KB
testcase_08 AC 14 ms
6,676 KB
testcase_09 AC 14 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 13 ms
6,676 KB
testcase_12 AC 14 ms
6,676 KB
testcase_13 AC 11 ms
6,676 KB
testcase_14 AC 24 ms
6,676 KB
testcase_15 AC 26 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 20 ms
6,676 KB
testcase_21 AC 11 ms
6,676 KB
testcase_22 AC 14 ms
6,676 KB
testcase_23 AC 4 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 5 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 7 ms
6,676 KB
testcase_30 AC 36 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
//use itertools::{iproduct, Itertools};
//use proconio::input;
//use proconio::marker::*;
use std::collections::*;

fn main() {
    input! {
        n:usize,
        m:usize,
        a:[i64;n],
        uvw:[(usize1,usize1,i64);m],
    }

    let uvw = uvw
        .into_iter()
        .filter_map(|(u, v, w)| {
            if u != n - 1 {
                Some((u, v, -a[u] + w))
            } else {
                None
            }
        })
        .collect::<Vec<_>>();

    const INF: i64 = std::i64::MAX;
    let mut dists = vec![INF; n];
    dists[0] = 0;
    let mut rep = 0;
    while rep < n {
        let mut end = true;
        for &(u, v, w) in uvw.iter() {
            if dists[u] != INF && dists[u] + w < dists[v] {
                dists[v] = dists[u] + w;
                end = false;
            }
        }

        if end {
            break;
        }
        rep += 1;
    }
    if rep == n {
        println!("inf");
    } else {
        let ans = -dists[n - 1] + a[n - 1];
        println!("{}", ans);
    }
}

use input::*;
mod input {
    #[macro_export]
    macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
        ($($r:tt)*) => {
            let 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_export]
    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_export]
    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")
        };
    }
}
0