結果

問題 No.2712 Play more!
ユーザー ra5anchorra5anchor
提出日時 2024-04-13 09:54:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,239 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 77,672 KB
最終ジャッジ日時 2024-04-13 09:54:24
合計ジャッジ時間 6,497 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
53,020 KB
testcase_01 AC 42 ms
52,776 KB
testcase_02 AC 37 ms
53,052 KB
testcase_03 AC 38 ms
52,748 KB
testcase_04 AC 37 ms
52,460 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 206 ms
77,260 KB
testcase_10 AC 35 ms
53,004 KB
testcase_11 AC 154 ms
77,140 KB
testcase_12 AC 242 ms
77,032 KB
testcase_13 AC 143 ms
76,924 KB
testcase_14 WA -
testcase_15 AC 489 ms
77,600 KB
testcase_16 AC 110 ms
77,088 KB
testcase_17 AC 69 ms
75,084 KB
testcase_18 AC 99 ms
76,404 KB
testcase_19 AC 84 ms
76,628 KB
testcase_20 AC 176 ms
77,412 KB
testcase_21 AC 116 ms
77,152 KB
testcase_22 AC 304 ms
77,452 KB
testcase_23 AC 83 ms
76,844 KB
testcase_24 AC 120 ms
76,812 KB
testcase_25 AC 83 ms
76,776 KB
testcase_26 AC 115 ms
76,676 KB
testcase_27 WA -
testcase_28 AC 67 ms
67,060 KB
testcase_29 AC 123 ms
76,860 KB
testcase_30 AC 258 ms
77,396 KB
testcase_31 AC 70 ms
77,672 KB
testcase_32 AC 75 ms
75,052 KB
testcase_33 AC 38 ms
55,236 KB
testcase_34 AC 38 ms
53,568 KB
testcase_35 AC 34 ms
52,748 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:
            check = score[N-1]
            for u, v, weight in E:
                if score[v] < score[u] + weight:
                    score[v] = score[u] + weight
                    update = True
            check2 = score[N-1]
            if check == check2:
                print(check)
                exit()
            else:
                return -1
    return score
# print(E)
score = BF(0) # ノード0から各地点の最短距離
if score == -1:
    print('inf')
else:
    print(score[N-1])
0