結果

問題 No.788 トラックの移動
ユーザー takeya_okinotakeya_okino
提出日時 2022-07-13 22:34:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,324 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 18,360 KB
最終ジャッジ日時 2023-09-07 09:18:32
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0