結果
問題 | No.2712 Play more! |
ユーザー | budou |
提出日時 | 2024-04-11 13:37:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 388 ms / 2,000 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 79,172 KB |
最終ジャッジ日時 | 2024-04-11 13:37:57 |
合計ジャッジ時間 | 7,633 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
68,680 KB |
testcase_01 | AC | 64 ms
67,624 KB |
testcase_02 | AC | 64 ms
67,232 KB |
testcase_03 | AC | 63 ms
67,580 KB |
testcase_04 | AC | 62 ms
67,104 KB |
testcase_05 | AC | 63 ms
68,104 KB |
testcase_06 | AC | 64 ms
67,828 KB |
testcase_07 | AC | 221 ms
78,848 KB |
testcase_08 | AC | 197 ms
78,572 KB |
testcase_09 | AC | 201 ms
78,616 KB |
testcase_10 | AC | 64 ms
66,988 KB |
testcase_11 | AC | 179 ms
78,364 KB |
testcase_12 | AC | 245 ms
78,436 KB |
testcase_13 | AC | 174 ms
78,276 KB |
testcase_14 | AC | 206 ms
79,168 KB |
testcase_15 | AC | 388 ms
78,936 KB |
testcase_16 | AC | 126 ms
78,864 KB |
testcase_17 | AC | 85 ms
74,812 KB |
testcase_18 | AC | 123 ms
78,356 KB |
testcase_19 | AC | 109 ms
78,280 KB |
testcase_20 | AC | 196 ms
78,896 KB |
testcase_21 | AC | 165 ms
78,716 KB |
testcase_22 | AC | 233 ms
78,468 KB |
testcase_23 | AC | 105 ms
78,884 KB |
testcase_24 | AC | 145 ms
78,524 KB |
testcase_25 | AC | 100 ms
78,292 KB |
testcase_26 | AC | 139 ms
78,296 KB |
testcase_27 | AC | 121 ms
78,824 KB |
testcase_28 | AC | 79 ms
73,560 KB |
testcase_29 | AC | 141 ms
78,892 KB |
testcase_30 | AC | 340 ms
79,172 KB |
testcase_31 | AC | 90 ms
78,520 KB |
testcase_32 | AC | 87 ms
78,672 KB |
testcase_33 | AC | 65 ms
68,312 KB |
testcase_34 | AC | 62 ms
67,120 KB |
testcase_35 | AC | 63 ms
67,512 KB |
ソースコード
import typing import sys from collections import deque, defaultdict input = lambda: sys.stdin.readline().strip() inf = 10**18 mod = 998244353 def BellmanFord(N, s, Edges): dist = [inf for _ in range(N)] dist[s] = 0 # N-1回緩める for _ in range(N-1): changed = False for v_from, v_to, c in Edges: if dist[v_from] == inf: continue if dist[v_from]+c < dist[v_to]: dist[v_to] = dist[v_from]+c changed = True if not changed: return dist for _ in range(N-1): changed = False for v_from, v_to, c in Edges: # 非連結の場合はあり得る if dist[v_from] == inf: continue # -inf + c が -inf以外の何よりも小さいようなinfの値を選択する if dist[v_from]+c < dist[v_to]: dist[v_to] = -inf changed = True if not changed: return dist return dist def solve(): N, M = map(int, input().split()) A = list(map(int, input().split())) Edges = [] # (v_from, v_to, cost) for _ in range(M): a, b, c = map(int, input().split()) # v_fromを攻略して移動し,v_toへと到達する時間 Edges.append((a-1, b-1, c-A[a-1])) dist = BellmanFord(N, 0, Edges) if dist[-1] == -inf: print('inf') return # Nを攻略する時間を足す print(-dist[-1]+A[-1]) def main(): t = 1 for _ in range(t): solve() main()