結果
| 問題 |
No.2712 Play more!
|
| ユーザー |
timi
|
| 提出日時 | 2024-04-06 12:52:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 903 bytes |
| コンパイル時間 | 166 ms |
| コンパイル使用メモリ | 82,596 KB |
| 実行使用メモリ | 78,636 KB |
| 最終ジャッジ日時 | 2024-10-01 03:49:05 |
| 合計ジャッジ時間 | 7,173 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 6 |
ソースコード
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):
for x, y, z in g:
if d[y] > d[x] + z and d[x]!=float('inf'):
d[y] = d[x] + z
if i == n-1 and y==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(V,g)
ans=bellman_ford(0)
#print(ans)
if ans==-1:
print('inf')
else:
print(A[0]-ans[-1])
timi