結果
| 問題 | No.2712 Play more! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-03-31 19:07:30 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 491 ms / 2,000 ms | 
| コード長 | 1,172 bytes | 
| コンパイル時間 | 232 ms | 
| コンパイル使用メモリ | 82,380 KB | 
| 実行使用メモリ | 78,040 KB | 
| 最終ジャッジ日時 | 2024-09-30 23:52:58 | 
| 合計ジャッジ時間 | 6,264 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 | 
ソースコード
# 標準入力された値を整数に変換する
def INT():
    return int(input())
# 標準入力された複数の値を整数に変換する
def MI():
    return map(int, input().split())
# 標準入力された複数の値を整数のリストに変換する
def LI():
    return list(map(int, input().split()))
N, M = MI()
A = LI()
G = [[] for i in range(N)]
for _ in range(M):
    a, b, c = MI()
    a -= 1
    b -= 1
    G[a].append((b, c - A[b]))
MINF = 10**18
dist = [MINF] * N
dist[0] = -A[0]
exist_negative_cycle = False
for i in range(N):
    update = False
    for u in range(N):
        if dist[u] == MINF:
            continue
        for v, c in G[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                update = True
    if not update:
        break
    if i == N - 1 and update:
        exist_negative_cycle = True
for i in range(N):
    for u in range(N):
        if dist[u] == MINF:
            continue
        for v, c in G[u]:
            threshold = dist[u] + c
            if threshold < dist[v]:
                dist[v] = -MINF
ans = -dist[N - 1]
print(ans if dist[N - 1] != -MINF else "inf")
            
            
            
        