結果

問題 No.2712 Play more!
コンテスト
ユーザー LyricalMaestro
提出日時 2026-03-10 00:29:49
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 923 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 368 ms
コンパイル使用メモリ 85,760 KB
実行使用メモリ 79,192 KB
最終ジャッジ日時 2026-03-10 00:29:56
合計ジャッジ時間 4,113 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2712

MAX_INT = 10 ** 18

def 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())
        edges.append((a, b, c))

    new_edges = []
    for a, b, c in edges:
        new_edges.append((a, b, -A[b - 1] + c))
    
    new_edges.append((0, 1, -A[0]))

    # ベルマンフォード
    costs = [MAX_INT] * (N + 1)
    costs[0] = 0

    for i in range(N + 1):

        for a, b, c in new_edges:
            new_cost = costs[a] + c
            if costs[b] > new_cost:
                if i >= N:
                    costs[b] = -MAX_INT
                else:
                    costs[b] = new_cost

    for i in range(N + 1):
        if costs[i] == - MAX_INT:
            print("inf")
            return 
    
    print(-costs[N])







if __name__ == "__main__":
    main()
0