結果

問題 No.17 2つの地点に泊まりたい
ユーザー phsplsphspls
提出日時 2022-09-01 02:17:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,425 bytes
コンパイル時間 4,584 ms
コンパイル使用メモリ 159,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 07:27:26
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let s = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: usize = temp.trim().parse().unwrap();
            temp
        })
        .collect::<Vec<usize>>();
    let mut m = String::new();
    std::io::stdin().read_line(&mut m).ok();
    let m: usize = m.trim().parse().unwrap();
    let mut paths = vec![vec![INF; n]; n];
    for _ in 0..m {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).ok();
        let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = temp[0];
        let b = temp[1];
        let c = temp[2];
        paths[a][b] = c;
        paths[b][a] = c;
    }
    for i in 0..n { paths[i][i] = 0; }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                paths[i][j] = paths[i][j].min(paths[i][k] + paths[k][j]);
            }
        }
    }
    let mut result = INF;
    for i in 1..n-1 {
        for j in i+1..n-1 {
            result = result.min(s[i]+s[j]+paths[0][i]+paths[i][j]+paths[j][n-1]);
            result = result.min(s[i]+s[j]+paths[0][j]+paths[i][j]+paths[i][n-1]);
        }
    }
    println!("{}", result);
}
0