結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー koba-e964koba-e964
提出日時 2021-11-09 22:40:29
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,247 bytes
コンパイル時間 11,550 ms
コンパイル使用メモリ 388,144 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-29 21:28:44
合計ジャッジ時間 20,085 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 473 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 371 ms
5,376 KB
testcase_12 AC 142 ms
5,376 KB
testcase_13 AC 229 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 138 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 204 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 372 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 266 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 42 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 330 ms
5,376 KB
testcase_34 AC 157 ms
5,376 KB
testcase_35 AC 40 ms
5,376 KB
testcase_36 AC 34 ms
5,376 KB
testcase_37 AC 8 ms
5,376 KB
testcase_38 AC 90 ms
5,376 KB
testcase_39 AC 13 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 0 ms
5,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 238 ms
5,376 KB
testcase_49 AC 25 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 46 ms
5,376 KB
testcase_53 AC 25 ms
5,376 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 403 ms
5,376 KB
testcase_58 AC 411 ms
5,376 KB
testcase_59 AC 412 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::collections::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const INF: i64 = 1 << 50;

fn main() {
    input! {
        t: i32,
        n: usize, m: usize,
        abc: [(usize1, usize1, i64); m],
    }
    let mut mi = INF;
    for i in 0..m {
        let mut g = vec![vec![]; n];
        for j in 0..m {
            if i == j { continue; }
            let (a, b, c) = abc[j];
            g[a].push((b, c));
            if t == 0 {
                g[b].push((a, c));
            }
        }
        let mut dist = vec![INF; n];
        let mut que = BinaryHeap::new();
        let (ai, bi, ci) = abc[i];
        que.push((Reverse(0), bi));
        while let Some((Reverse(d), v)) = que.pop() {
            if dist[v] <= d { continue; }
            dist[v] = d;
            for &(w, c) in &g[v] {
                que.push((Reverse(d + c), w));
            }
        }
        mi = min(mi, dist[ai] + ci);
    }
    println!("{}", if mi >= INF { 0 } else { mi });
}
0