結果
問題 | No.2712 Play more! |
ユーザー |
|
提出日時 | 2024-03-31 15:09:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 953 bytes |
コンパイル時間 | 370 ms |
コンパイル使用メモリ | 82,652 KB |
実行使用メモリ | 78,664 KB |
最終ジャッジ日時 | 2024-09-30 20:20:38 |
合計ジャッジ時間 | 12,647 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 2 |
ソースコード
from collections import namedtupleEdge = namedtuple("Edge", ["from_", "to", "cost"])def bellman_ford(st, dist, edges):N = len(dist)for i in range(N):dist[i] = -float('inf')dist[st] = 0for _ in range(N):update = Falsefor e in edges:if dist[e.to] < dist[e.from_] + e.cost:dist[e.to] = dist[e.from_] + e.costupdate = Trueif not update:return Truereturn Falseif __name__ == "__main__":N, M = map(int, input().split())A = list(map(int, input().split()))edges = []for _ in range(M):a, b, c = map(int, input().split())a -= 1b -= 1edges.append(Edge(a + N, b, -c))for i in range(N):edges.append(Edge(i, i + N, A[i]))dist = [-float('inf')] * (2 * N)f = bellman_ford(0, dist, edges)if f:print(dist[2 * N - 1])else:print("inf")