結果

問題 No.2712 Play more!
ユーザー rlangevinrlangevin
提出日時 2024-04-01 22:24:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,064 KB
最終ジャッジ日時 2024-04-03 12:12:12
合計ジャッジ時間 7,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 39 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 322 ms
76,824 KB
testcase_08 AC 265 ms
77,064 KB
testcase_09 AC 322 ms
76,824 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 172 ms
76,432 KB
testcase_12 AC 470 ms
76,828 KB
testcase_13 AC 183 ms
76,436 KB
testcase_14 AC 332 ms
76,828 KB
testcase_15 AC 642 ms
76,948 KB
testcase_16 AC 137 ms
76,316 KB
testcase_17 AC 88 ms
76,060 KB
testcase_18 AC 140 ms
76,440 KB
testcase_19 AC 113 ms
76,336 KB
testcase_20 AC 248 ms
76,552 KB
testcase_21 AC 124 ms
76,272 KB
testcase_22 AC 492 ms
76,956 KB
testcase_23 AC 94 ms
76,288 KB
testcase_24 AC 151 ms
76,436 KB
testcase_25 AC 82 ms
74,640 KB
testcase_26 AC 158 ms
76,452 KB
testcase_27 AC 141 ms
76,700 KB
testcase_28 AC 165 ms
75,692 KB
testcase_29 AC 141 ms
76,452 KB
testcase_30 AC 484 ms
76,948 KB
testcase_31 AC 523 ms
76,692 KB
testcase_32 AC 387 ms
76,692 KB
testcase_33 AC 50 ms
61,420 KB
testcase_34 AC 37 ms
53,460 KB
testcase_35 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def bellman_ford(G, s):
    inf = 10 ** 18
    N = len(G)
    dist = [inf] * N
    negative = [False] * N
    dist[s] = 0
    for _ in range(N - 1):
        for u in range(N):
            if dist[u] >= inf//2:
                continue
            for v, c in G[u]:
                if dist[v] > dist[u] + c:
                    dist[v] = dist[u] + c
                    
    for _ in range(N):
        for u in range(N):
            if dist[u] >= inf//2:
                continue
            for v, c in G[u]:
                if dist[v] > dist[u] + c:
                    negative[v] = True
                if negative[u]:
                    negative[v] = True
                    
    return dist, negative

N, M = map(int, input().split())
A = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a - 1 , b - 1
    G[a].append((b, c - A[a]))
    
d, f = bellman_ford(G, 0)
if f[-1]:
    print("inf")
else:
    print(-d[-1]+A[-1])
0