結果

問題 No.2712 Play more!
ユーザー 👑 rin204rin204
提出日時 2024-04-07 14:33:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,076 KB
最終ジャッジ日時 2024-04-07 14:33:36
合計ジャッジ時間 9,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 WA -
testcase_04 AC 39 ms
53,460 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 523 ms
74,132 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 249 ms
72,968 KB
testcase_12 WA -
testcase_13 AC 198 ms
72,980 KB
testcase_14 WA -
testcase_15 AC 837 ms
76,820 KB
testcase_16 AC 138 ms
72,968 KB
testcase_17 AC 80 ms
72,980 KB
testcase_18 AC 151 ms
72,996 KB
testcase_19 AC 105 ms
73,008 KB
testcase_20 AC 270 ms
72,968 KB
testcase_21 AC 205 ms
73,580 KB
testcase_22 AC 692 ms
76,820 KB
testcase_23 AC 101 ms
73,068 KB
testcase_24 AC 163 ms
72,980 KB
testcase_25 AC 79 ms
72,968 KB
testcase_26 AC 191 ms
72,980 KB
testcase_27 WA -
testcase_28 AC 82 ms
66,352 KB
testcase_29 AC 166 ms
72,980 KB
testcase_30 AC 710 ms
76,948 KB
testcase_31 AC 78 ms
76,948 KB
testcase_32 AC 79 ms
76,820 KB
testcase_33 AC 45 ms
61,164 KB
testcase_34 AC 35 ms
53,460 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def bellmanFord(n, edges, s, inf=1 << 60):
    """
    edges = [(from1, to1, cost1), (from2, to2, cost2), ...)]
    """
    dist = [inf] * n
    dist[s] = 0

    for _ in range(n):
        update = False
        for u, v, d in edges:
            if dist[u] != inf and dist[v] > dist[u] + d:
                dist[v] = dist[u] + d
                update = True

        if not update:
            return -dist[-1]

    update = False
    for u, v, d in edges:
        if dist[u] != inf and dist[v] > dist[u] + d:
            dist[v] = dist[u] + d
            if v == n - 1:
                return "inf"

    return -dist[-1]


n, m = map(int, input().split())
A = list(map(int, input().split()))
edges = []
for i, a in enumerate(A):
    edges.append((2 * i, 2 * i + 1, -a))
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((2 * a + 1, 2 * b, c))

ans = bellmanFord(2 * n, edges, 0)
print(ans)
0