結果
問題 |
No.788 トラックの移動
|
ユーザー |
![]() |
提出日時 | 2023-10-03 08:56:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,404 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 118,776 KB |
最終ジャッジ日時 | 2024-07-26 13:59:13 |
合計ジャッジ時間 | 11,856 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 2 |
ソースコード
import sys readline = sys.stdin.readline from heapq import heappush, heappop inf = float('inf') def dijkstra(s, g, N): # ゴールがない場合はg=-1とする。 def cost(v, m): return v * N + m dist = [inf] * N mindist = [inf] * N seen = [False] * N Q = [cost(0, s)] while Q: c, m = divmod(heappop(Q), N) if seen[m]: continue seen[m] = True dist[m] = c if m == g: return dist #------heapをアップデートする。-------- for u, C in G[m]: if seen[u]: continue newdist = dist[m] + C #------------------------------------ if newdist >= mindist[u]: continue mindist[u] = newdist heappush(Q, cost(newdist, u)) return dist N, M, L = map(int, input().split()) L -= 1 T = list(map(int, input().split())) G = [[] for i in range(N)] for i in range(M): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 G[a].append((b, c)) G[b].append((a, c)) D = [] for i in range(N): D.append(dijkstra(i, -1, N)) ans = inf for i in range(N): S = 0 for j in range(N): S += D[i][j] * T[j] * 2 for j in range(N): temp = D[L][j] + D[j][i] if T[j]: temp -= 2 * D[i][j] ans = min(ans, S + temp) print(ans)