結果

問題 No.2712 Play more!
ユーザー ra5anchorra5anchor
提出日時 2024-04-13 09:47:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 903 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 77,688 KB
最終ジャッジ日時 2024-04-13 09:47:43
合計ジャッジ時間 7,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,748 KB
testcase_01 AC 64 ms
53,272 KB
testcase_02 AC 42 ms
53,212 KB
testcase_03 AC 40 ms
52,372 KB
testcase_04 WA -
testcase_05 AC 39 ms
52,524 KB
testcase_06 AC 38 ms
53,104 KB
testcase_07 AC 282 ms
77,544 KB
testcase_08 AC 244 ms
77,268 KB
testcase_09 AC 231 ms
77,168 KB
testcase_10 WA -
testcase_11 AC 173 ms
77,144 KB
testcase_12 AC 298 ms
77,212 KB
testcase_13 AC 162 ms
76,576 KB
testcase_14 AC 202 ms
77,164 KB
testcase_15 AC 471 ms
77,308 KB
testcase_16 AC 116 ms
76,888 KB
testcase_17 AC 85 ms
75,084 KB
testcase_18 AC 134 ms
76,892 KB
testcase_19 AC 105 ms
76,720 KB
testcase_20 AC 207 ms
76,760 KB
testcase_21 AC 129 ms
77,088 KB
testcase_22 AC 376 ms
77,244 KB
testcase_23 AC 91 ms
76,624 KB
testcase_24 AC 129 ms
76,560 KB
testcase_25 AC 78 ms
73,980 KB
testcase_26 AC 134 ms
76,532 KB
testcase_27 AC 156 ms
74,444 KB
testcase_28 AC 67 ms
66,176 KB
testcase_29 AC 136 ms
76,588 KB
testcase_30 AC 282 ms
77,220 KB
testcase_31 AC 82 ms
77,688 KB
testcase_32 AC 76 ms
74,484 KB
testcase_33 AC 45 ms
54,716 KB
testcase_34 AC 37 ms
52,964 KB
testcase_35 AC 38 ms
52,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))

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

def BF(start):
    # Bellman-Ford
    score = [-float('inf')] * N # スタート地点からの最小距離
    score[start] = A[start]

    for i in range(N):
        update = False # 更新が行われたか
        for u, v, weight in E:
            if score[v] < score[u] + weight:
                score[v] = score[u] + weight
                update = True
        if not update:
            break
        # 負閉路が存在するときは-1を返す
        if i == N - 1:
            return -1
    return score
# print(E)
score = BF(0) # ノード0から各地点の最短距離
if score == -1:
    print('inf')
else:
    print(score[N-1])
0