結果

問題 No.2712 Play more!
ユーザー prd_xxx
提出日時 2024-03-31 14:53:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,736 KB
実行使用メモリ 77,988 KB
最終ジャッジ日時 2024-09-30 23:48:31
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = list(map(int,input().split()))
ABC = [tuple(map(int,input().split())) for _ in range(M)]

es = [[] for _ in range(N)]
rs = [[] for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    es[a].append(b)
    rs[b].append(a)

stack = [0]
vis_go = set([0])
while stack:
    v = stack.pop()
    for to in es[v]:
        if to in vis_go: continue
        vis_go.add(to)
        stack.append(to)
stack = [N-1]
vis_bk = set([N-1])
while stack:
    v = stack.pop()
    for to in rs[v]:
        if to in vis_bk: continue
        vis_bk.add(to)
        stack.append(to)
use = vis_go & vis_bk


INF = 10**18
dist = [INF] * N
dist[0] = -A[0]
for i in range(len(use)):
    for a,b,c in ABC:
        a,b = a-1,b-1
        if a not in use: continue
        if b not in use: continue
        dd = c - A[b]
        if dist[b] > dist[a] + dd:
            dist[b] = dist[a] + dd
            if i==len(use)-1:
                exit(print('inf'))

print(-dist[-1])
0