結果
| 問題 |
No.2712 Play more!
|
| ユーザー |
|
| 提出日時 | 2024-03-31 14:19:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,203 bytes |
| コンパイル時間 | 360 ms |
| コンパイル使用メモリ | 82,156 KB |
| 実行使用メモリ | 93,140 KB |
| 最終ジャッジ日時 | 2024-09-30 19:22:21 |
| 合計ジャッジ時間 | 17,959 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 RE * 5 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
# O(EV)
g = []
n,m = map(int,input().split())
n *= 2
alist = list(map(int,input().split()))
edge = [[] for i in range(n//2)]
for i in range(m):
a,b,c = map(int,input().split())
edge[b-1].append(a-1)
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]))
start = n//2-1
d = collections.deque()
dist = [10**18 for i in range(n//2)]
d.append(start)
dist[start] = 0
while d:
now = d.popleft()
for i in edge[now]:
if dist[i] > dist[now] + 1:
dist[i] = dist[now] + 1
d.append(i)
d = [float('inf')]*n # 各頂点への最小コスト
d[0] = 0 # 自身への距離は0
for i in range(n):
update = False # 更新が行われたか
check = [False for rrfrf in range(n)]
for x, y, z in g:
if d[y] > d[x] + z:
d[y] = d[x] + z
update = True
check[y] = True
if not update:
break
if i == n-1:
for j in range(n-1):
if check[j] == True and dist[j] != 10**18:
exit(print('inf'))
print(-d[-1])