結果
問題 | No.845 最長の切符 |
ユーザー |
|
提出日時 | 2022-12-01 02:46:35 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 70 ms / 3,000 ms |
コード長 | 1,261 bytes |
コンパイル時間 | 16,730 ms |
コンパイル使用メモリ | 379,096 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-10-07 23:02:48 |
合計ジャッジ時間 | 18,485 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
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()); }