結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
takeya_okino
|
| 提出日時 | 2022-07-13 22:34:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,324 bytes |
| コンパイル時間 | 415 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 22,784 KB |
| 最終ジャッジ日時 | 2024-06-25 03:36:48 |
| 合計ジャッジ時間 | 7,012 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 13 |
ソースコード
from heapq import heappop, heappush
def dijkstra(start, dist, path):
candidate = [(0, start)]
while candidate:
cost, i = heappop(candidate)
if cost > dist[i]: continue
for c, j in path[i]:
if cost+c >= dist[j]: continue
dist[j] = cost+c
heappush(candidate, (cost+c, j))
inf = 10**18+1
n, m, l= map(int, input().split(" "))
t = list(map(int, input().split(" ")))
EDGES = [set() for _ in range(n)]
for i in range(m):
a, b, c = [int(x)-1 for x in input().split(" ")]
c += 1
EDGES[a].add((c, b))
EDGES[b].add((c, a))
ans = 10**18+1
to2 = [inf]*n
to2[l - 1] = 0
dijkstra(l - 1, to2, EDGES)
for i in range(n):
to_ = [inf]*n
to_[i] = 0
dijkstra(i, to_, EDGES)
w = 0
if i == (l - 1):
for j in range(n):
w += (to_[j] * t[j])
w = 2 * w
else:
if t[l - 1] > 0:
w1 = to_[l - 1]
w2 = 0
for j in range(n):
w2 += (to_[j] * t[j] * 2)
w2 -= (to_[l - 1] * 2)
w = w1 + w2
else:
w1 = 0
w2 = 0
for j in range(n):
w1 = 0
w2 = 0
if t[j] > 0:
w1 = to2[j]
w1 += to_[j]
for k in range(n):
w2 += (to_[k] * t[k] * 2)
w2 -= (to_[j] * 2)
w = w1 + w2
ans = min(ans, w)
ans = min(ans, w)
print(ans)
takeya_okino