結果

問題 No.2712 Play more!
ユーザー RYOH2718RYOH2718
提出日時 2024-03-31 19:07:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,700 KB
最終ジャッジ日時 2024-04-03 12:11:31
合計ジャッジ時間 6,652 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 41 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 229 ms
76,688 KB
testcase_08 AC 278 ms
77,700 KB
testcase_09 AC 227 ms
76,816 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 170 ms
76,424 KB
testcase_12 AC 357 ms
76,820 KB
testcase_13 AC 168 ms
76,432 KB
testcase_14 AC 253 ms
76,704 KB
testcase_15 AC 554 ms
76,948 KB
testcase_16 AC 120 ms
76,312 KB
testcase_17 AC 90 ms
76,312 KB
testcase_18 AC 122 ms
76,448 KB
testcase_19 AC 109 ms
76,324 KB
testcase_20 AC 209 ms
76,544 KB
testcase_21 AC 131 ms
76,404 KB
testcase_22 AC 329 ms
76,948 KB
testcase_23 AC 95 ms
76,148 KB
testcase_24 AC 141 ms
76,440 KB
testcase_25 AC 90 ms
76,168 KB
testcase_26 AC 140 ms
76,448 KB
testcase_27 AC 133 ms
76,576 KB
testcase_28 AC 117 ms
70,652 KB
testcase_29 AC 136 ms
76,440 KB
testcase_30 AC 408 ms
76,820 KB
testcase_31 AC 267 ms
76,948 KB
testcase_32 AC 214 ms
76,948 KB
testcase_33 AC 47 ms
61,636 KB
testcase_34 AC 36 ms
53,460 KB
testcase_35 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 標準入力された値を整数に変換する
def INT():
    return int(input())


# 標準入力された複数の値を整数に変換する
def MI():
    return map(int, input().split())


# 標準入力された複数の値を整数のリストに変換する
def LI():
    return list(map(int, input().split()))


N, M = MI()
A = LI()
G = [[] for i in range(N)]
for _ in range(M):
    a, b, c = MI()
    a -= 1
    b -= 1
    G[a].append((b, c - A[b]))

MINF = 10**18
dist = [MINF] * N
dist[0] = -A[0]
exist_negative_cycle = False
for i in range(N):
    update = False
    for u in range(N):
        if dist[u] == MINF:
            continue
        for v, c in G[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                update = True

    if not update:
        break

    if i == N - 1 and update:
        exist_negative_cycle = True

for i in range(N):
    for u in range(N):
        if dist[u] == MINF:
            continue
        for v, c in G[u]:
            threshold = dist[u] + c
            if threshold < dist[v]:
                dist[v] = -MINF

ans = -dist[N - 1]
print(ans if dist[N - 1] != -MINF else "inf")
0