結果

問題 No.2712 Play more!
ユーザー pitPpitP
提出日時 2024-03-31 15:09:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,332 KB
最終ジャッジ日時 2024-03-31 15:09:57
合計ジャッジ時間 14,677 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,604 KB
testcase_01 AC 41 ms
55,604 KB
testcase_02 AC 41 ms
55,604 KB
testcase_03 AC 41 ms
55,604 KB
testcase_04 WA -
testcase_05 AC 44 ms
60,912 KB
testcase_06 AC 41 ms
55,604 KB
testcase_07 AC 914 ms
77,308 KB
testcase_08 AC 1,165 ms
77,432 KB
testcase_09 AC 914 ms
77,308 KB
testcase_10 WA -
testcase_11 AC 410 ms
77,192 KB
testcase_12 AC 1,050 ms
77,564 KB
testcase_13 AC 352 ms
77,064 KB
testcase_14 AC 759 ms
77,308 KB
testcase_15 AC 1,639 ms
78,332 KB
testcase_16 AC 184 ms
77,192 KB
testcase_17 AC 118 ms
76,808 KB
testcase_18 AC 220 ms
77,064 KB
testcase_19 AC 153 ms
76,808 KB
testcase_20 AC 470 ms
77,192 KB
testcase_21 AC 235 ms
77,320 KB
testcase_22 AC 1,044 ms
77,564 KB
testcase_23 AC 123 ms
77,192 KB
testcase_24 AC 288 ms
77,064 KB
testcase_25 AC 106 ms
77,192 KB
testcase_26 AC 294 ms
77,064 KB
testcase_27 AC 495 ms
77,176 KB
testcase_28 AC 147 ms
76,524 KB
testcase_29 AC 239 ms
77,064 KB
testcase_30 AC 1,054 ms
77,436 KB
testcase_31 AC 100 ms
77,308 KB
testcase_32 AC 101 ms
77,180 KB
testcase_33 AC 59 ms
65,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import namedtuple

Edge = namedtuple("Edge", ["from_", "to", "cost"])

def bellman_ford(st, dist, edges):
    N = len(dist)
    for i in range(N):
        dist[i] = -float('inf')
    dist[st] = 0
    for _ in range(N):
        update = False
        for e in edges:
            if dist[e.to] < dist[e.from_] + e.cost:
                dist[e.to] = dist[e.from_] + e.cost
                update = True
        if not update:
            return True
    return False

if __name__ == "__main__":
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        edges.append(Edge(a + N, b, -c))
    for i in range(N):
        edges.append(Edge(i, i + N, A[i]))

    dist = [-float('inf')] * (2 * N)
    f = bellman_ford(0, dist, edges)
    if f:
        print(dist[2 * N - 1])
    else:
        print("inf")
0