結果

問題 No.2712 Play more!
ユーザー hato336hato336
提出日時 2024-03-31 14:07:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 90,680 KB
最終ジャッジ日時 2024-03-31 14:08:10
合計ジャッジ時間 16,021 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
84,920 KB
testcase_01 AC 130 ms
84,920 KB
testcase_02 AC 131 ms
84,920 KB
testcase_03 AC 130 ms
84,920 KB
testcase_04 WA -
testcase_05 AC 132 ms
84,920 KB
testcase_06 AC 132 ms
84,920 KB
testcase_07 AC 1,038 ms
89,528 KB
testcase_08 AC 805 ms
90,296 KB
testcase_09 AC 1,017 ms
89,528 KB
testcase_10 WA -
testcase_11 AC 437 ms
89,528 KB
testcase_12 AC 1,013 ms
90,040 KB
testcase_13 AC 384 ms
89,528 KB
testcase_14 AC 750 ms
89,656 KB
testcase_15 AC 1,444 ms
90,680 KB
testcase_16 AC 256 ms
89,528 KB
testcase_17 AC 194 ms
89,400 KB
testcase_18 AC 294 ms
89,528 KB
testcase_19 AC 227 ms
89,528 KB
testcase_20 AC 482 ms
89,528 KB
testcase_21 AC 307 ms
89,656 KB
testcase_22 AC 999 ms
89,912 KB
testcase_23 AC 210 ms
89,528 KB
testcase_24 AC 327 ms
89,528 KB
testcase_25 AC 183 ms
89,400 KB
testcase_26 AC 342 ms
89,528 KB
testcase_27 AC 526 ms
89,528 KB
testcase_28 AC 210 ms
89,144 KB
testcase_29 AC 294 ms
89,528 KB
testcase_30 AC 1,000 ms
89,784 KB
testcase_31 AC 176 ms
89,528 KB
testcase_32 AC 179 ms
89,528 KB
testcase_33 AC 147 ms
88,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    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 = []


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])
0