結果

問題 No.2712 Play more!
ユーザー 👑 KA37RIKA37RI
提出日時 2024-03-31 15:31:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,604 KB
最終ジャッジ日時 2024-03-31 15:31:47
合計ジャッジ時間 3,263 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 35 ms
53,460 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 68 ms
73,232 KB
testcase_08 AC 68 ms
73,232 KB
testcase_09 AC 68 ms
73,232 KB
testcase_10 WA -
testcase_11 AC 68 ms
72,952 KB
testcase_12 AC 68 ms
73,360 KB
testcase_13 AC 67 ms
72,952 KB
testcase_14 AC 68 ms
72,988 KB
testcase_15 AC 76 ms
76,560 KB
testcase_16 AC 67 ms
72,952 KB
testcase_17 AC 66 ms
72,952 KB
testcase_18 AC 65 ms
70,888 KB
testcase_19 AC 65 ms
70,888 KB
testcase_20 AC 68 ms
73,336 KB
testcase_21 AC 71 ms
76,408 KB
testcase_22 AC 70 ms
74,000 KB
testcase_23 AC 75 ms
76,536 KB
testcase_24 AC 68 ms
72,952 KB
testcase_25 AC 69 ms
73,336 KB
testcase_26 AC 67 ms
70,884 KB
testcase_27 RE -
testcase_28 WA -
testcase_29 AC 69 ms
72,952 KB
testcase_30 AC 73 ms
73,872 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def solve(n, m, a, uvw):
  graph = [[] for _ in range(n)]
  for ui, vi, wi in uvw:
    graph[ui-1].append((vi - 1, wi))

  pq = [(-a[0], 0)]
  mn = [10 ** 18] * n
  mn[0] = -a[0]
  while True:
    cost, node = heapq.heappop(pq)
    if node == n - 1:
      return -cost
    if mn[node] < cost:
      continue
    if cost < mn[node]:
      return "inf"
    for next_node, next_cost in graph[node]:
      if a[next_node] <= -cost - next_cost:
        continue
      a[next_node] = -cost + next_cost
      heapq.heappush(pq, (-a[next_node], next_node))

n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
uvw = [[int(x) for x in input().split()] for _ in range(m)]

print(solve(n, m, a, uvw))
0