結果

問題 No.2712 Play more!
ユーザー titia
提出日時 2024-04-30 03:18:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 77,524 KB
最終ジャッジ日時 2024-11-19 15:22:10
合計ジャッジ時間 6,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=list(map(int,input().split()))

E=[[] for i in range(N)]
E_INV=[[] for i in range(N)]

for i in range(M):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    E[a].append((b,c))
    E_INV[b].append(a)

USE=[0]*N
USE[N-1]=1
Q=[N-1]

while Q:
    x=Q.pop()
    for to in E_INV[x]:
        if USE[to]==0:
            USE[to]=1
            Q.append(to)

DP=[-1<<60]*N
DP[0]=A[0]

for tests in range(N+10):
    flag=0
    for i in range(N):
        if USE[i]==0:
            continue
        for to,c in E[i]:
            if USE[to]==0:
                continue
            if DP[to]<DP[i]+A[to]-c:
                DP[to]=DP[i]+A[to]-c
                flag=1

if flag==1:
    print("inf")
else:
    print(DP[-1])
0