結果

問題 No.845 最長の切符
ユーザー phsplsphspls
提出日時 2022-12-01 02:46:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 68 ms / 3,000 ms
コード長 1,261 bytes
コンパイル時間 4,261 ms
コンパイル使用メモリ 157,824 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-16 20:20:25
合計ジャッジ時間 2,636 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 53 ms
12,544 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 25 ms
6,784 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 60 ms
12,672 KB
testcase_21 AC 68 ms
12,800 KB
testcase_22 AC 12 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 54 ms
12,672 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 15 ms
12,672 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 15 ms
12,672 KB
testcase_29 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: isize = 1isize << 60;

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    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]-1;
        let b = temp[1]-1;
        let c = temp[2] as isize;
        paths[a][b] = paths[a][b].max(c);
        paths[b][a] = paths[b][a].max(c);
    }

    let mut dp = vec![vec![-INF; n]; 1<<n];
    for i in 0..n {
        dp[1usize<<i][i] = 0;
    }
    for i in 1..1<<n {
        for from in 0..n {
            if dp[i][from] == -INF { continue; }
            for to in 0..n {
                if ((i >> to) & 1) == 1 { continue; }
                if paths[from][to] == -INF { continue; }
                let nidx = i | (1 << to);
                dp[nidx][to] = dp[nidx][to].max(dp[i][from] + paths[from][to]);
            }
        }
    }
    println!("{}", dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap());
}
0