結果
問題 | No.1690 Power Grid |
ユーザー | neterukun |
提出日時 | 2021-09-24 22:19:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,634 ms / 3,000 ms |
コード長 | 1,305 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 81,648 KB |
実行使用メモリ | 115,696 KB |
最終ジャッジ日時 | 2024-07-05 10:50:22 |
合計ジャッジ時間 | 29,772 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,744 KB |
testcase_01 | AC | 34 ms
53,276 KB |
testcase_02 | AC | 37 ms
54,172 KB |
testcase_03 | AC | 34 ms
53,108 KB |
testcase_04 | AC | 39 ms
52,780 KB |
testcase_05 | AC | 37 ms
54,016 KB |
testcase_06 | AC | 1,305 ms
97,148 KB |
testcase_07 | AC | 1,307 ms
97,524 KB |
testcase_08 | AC | 1,275 ms
97,100 KB |
testcase_09 | AC | 1,287 ms
97,492 KB |
testcase_10 | AC | 254 ms
82,536 KB |
testcase_11 | AC | 2,466 ms
113,432 KB |
testcase_12 | AC | 38 ms
52,956 KB |
testcase_13 | AC | 70 ms
76,764 KB |
testcase_14 | AC | 233 ms
78,904 KB |
testcase_15 | AC | 2,634 ms
115,696 KB |
testcase_16 | AC | 1,313 ms
97,400 KB |
testcase_17 | AC | 696 ms
87,012 KB |
testcase_18 | AC | 329 ms
81,220 KB |
testcase_19 | AC | 1,297 ms
97,200 KB |
testcase_20 | AC | 1,315 ms
97,236 KB |
testcase_21 | AC | 159 ms
80,032 KB |
testcase_22 | AC | 2,102 ms
105,408 KB |
testcase_23 | AC | 2,588 ms
115,492 KB |
testcase_24 | AC | 2,333 ms
109,476 KB |
testcase_25 | AC | 2,416 ms
111,464 KB |
testcase_26 | AC | 2,508 ms
113,924 KB |
testcase_27 | AC | 37 ms
53,828 KB |
ソースコード
INF = 10 ** 18 def warshall_floyd(matrix): n = len(matrix) dist = [[d for d in row] for row in matrix] for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) return dist def cost(state, v): res = INF for nxt_v in range(n): if state & (1 << nxt_v): res = min(res, dist[v][nxt_v]) if res == INF: return 0 else: return res n, m, k = map(int, input().split()) a = list(map(int, input().split())) edges = [list(map(int, input().split())) for i in range(m)] matrix = [[INF] * n for i in range(n)] for i in range(n): matrix[i][i] = 0 for u, v, c in edges: u -= 1 v -= 1 matrix[u][v] = c matrix[v][u] = c dist = warshall_floyd(matrix) dp = [INF] * (1 << n) dp[0] = 0 for i in range(k): dq = [INF] * (1 << n) for bit_state in range(1 << n): if bin(bit_state).count("1") != i: continue for new_v in range(n): if bit_state & (1 << new_v): continue new_state = bit_state | (1 << new_v) dq[new_state] = min(dq[new_state], dp[bit_state] + a[new_v] + cost(bit_state, new_v)) dp, dq = dq, dp print(min(dp))