結果
| 問題 |
No.2712 Play more!
|
| ユーザー |
|
| 提出日時 | 2024-03-31 14:12:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 859 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 92,620 KB |
| 最終ジャッジ日時 | 2024-09-30 19:10:39 |
| 合計ジャッジ時間 | 25,004 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 4 TLE * 2 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
# O(EV)
def bellman_ford(s):
d = [float('inf')]*n # 各頂点への最小コスト
d[s] = 0 # 自身への距離は0
check = []
for i in range(2*n):
update = False # 更新が行われたか
for x, y, z in g:
if d[y] > d[x] + z:
d[y] = d[x] + z
update = True
check.append(d[-1])
# 負閉路が存在
if check[-1] != check[n-1]:
return -1
return d
g = []
n,m = map(int,input().split())
n *= 2
alist = list(map(int,input().split()))
for i in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
g.append((a*2+1,b*2,c))
for i in range(n//2):
g.append((i*2,i*2+1,-alist[i]))
z = bellman_ford(0)
print('inf' if z == -1 else -z[-1])