結果
問題 | No.788 トラックの移動 |
ユーザー | rlangevin |
提出日時 | 2023-10-03 08:56:01 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,404 bytes |
コンパイル時間 | 595 ms |
コンパイル使用メモリ | 87,060 KB |
実行使用メモリ | 119,260 KB |
最終ジャッジ日時 | 2023-10-03 08:56:17 |
合計ジャッジ時間 | 15,569 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 79 ms
71,412 KB |
testcase_02 | AC | 79 ms
71,580 KB |
testcase_03 | AC | 81 ms
71,208 KB |
testcase_04 | AC | 645 ms
87,420 KB |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | AC | 81 ms
71,208 KB |
testcase_08 | AC | 81 ms
71,364 KB |
testcase_09 | AC | 83 ms
71,112 KB |
testcase_10 | AC | 82 ms
71,116 KB |
testcase_11 | AC | 80 ms
71,256 KB |
testcase_12 | AC | 82 ms
71,244 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 841 ms
111,316 KB |
testcase_16 | AC | 1,891 ms
118,572 KB |
ソースコード
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)