結果

問題 No.2712 Play more!
ユーザー 👑 timitimi
提出日時 2024-04-06 13:12:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,836 KB
最終ジャッジ日時 2024-04-06 13:12:45
合計ジャッジ時間 6,530 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,616 KB
testcase_01 AC 43 ms
55,616 KB
testcase_02 AC 42 ms
55,616 KB
testcase_03 AC 42 ms
55,612 KB
testcase_04 AC 46 ms
55,616 KB
testcase_05 AC 43 ms
55,612 KB
testcase_06 AC 42 ms
55,616 KB
testcase_07 AC 239 ms
77,320 KB
testcase_08 AC 260 ms
77,568 KB
testcase_09 AC 238 ms
77,320 KB
testcase_10 AC 43 ms
55,612 KB
testcase_11 AC 177 ms
77,052 KB
testcase_12 AC 231 ms
77,324 KB
testcase_13 AC 166 ms
77,052 KB
testcase_14 AC 203 ms
77,332 KB
testcase_15 AC 425 ms
77,836 KB
testcase_16 AC 126 ms
77,184 KB
testcase_17 AC 90 ms
76,804 KB
testcase_18 AC 112 ms
76,688 KB
testcase_19 AC 106 ms
76,952 KB
testcase_20 AC 206 ms
77,304 KB
testcase_21 AC 151 ms
77,296 KB
testcase_22 AC 218 ms
77,452 KB
testcase_23 AC 103 ms
77,168 KB
testcase_24 AC 135 ms
76,928 KB
testcase_25 AC 91 ms
77,172 KB
testcase_26 AC 127 ms
76,948 KB
testcase_27 AC 93 ms
76,824 KB
testcase_28 AC 72 ms
68,284 KB
testcase_29 AC 147 ms
77,188 KB
testcase_30 AC 257 ms
77,452 KB
testcase_31 AC 93 ms
77,324 KB
testcase_32 AC 98 ms
77,204 KB
testcase_33 AC 49 ms
57,660 KB
testcase_34 AC 42 ms
55,616 KB
testcase_35 AC 42 ms
55,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=list(map(int, input().split()))
n=N
def bellman_ford(s):
    d = [float('inf')]*n # 各頂点への最小コスト
    d[s] = 0 # 自身への距離は0
    for i in range(n):
        update = False # 更新が行われたか
        for x, y, z in g:
            if d[y] > d[x] + z:
                d[y] = d[x] + z
                update = True
        if not update:
            break
        # 負閉路が存在
        if i == n - 1:
            return -1
    return d

 
g=[]
D=[[]for _ in range(N)];C=[]
for _ in range(M):
  x,y,z=map(int,input().split())
  x-=1;y-=1
  C.append((x,y,z))
  D[y].append(x)
  #g.append([x, y, -z])
  
from collections import deque
d=deque()
V=[-1]*N 
V[N-1]=1
d.append(N-1)
while d:
  now=d.popleft()
  for nex in D[now]:
    if V[nex]==-1:
      V[nex]=1
      d.append(nex)
      
for x,y,z in C:
  if V[x]+V[y]==2:
    g.append((x,y,-A[y]+z))
#print(g,D)
ans=bellman_ford(0)
#print(ans)
if ans==-1:
  print('inf')
else:
  print(A[0]-ans[-1])
0