結果

問題 No.2712 Play more!
ユーザー RYOH2718RYOH2718
提出日時 2024-03-31 15:26:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,241 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 130,352 KB
最終ジャッジ日時 2024-03-31 15:27:03
合計ジャッジ時間 14,614 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 WA -
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 366 ms
126,380 KB
testcase_08 AC 345 ms
124,116 KB
testcase_09 AC 415 ms
126,008 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 949 ms
125,576 KB
testcase_15 TLE -
testcase_16 WA -
testcase_17 AC 134 ms
76,820 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 627 ms
85,576 KB
testcase_21 AC 217 ms
77,740 KB
testcase_22 WA -
testcase_23 AC 204 ms
77,304 KB
testcase_24 WA -
testcase_25 AC 187 ms
77,188 KB
testcase_26 WA -
testcase_27 AC 205 ms
117,252 KB
testcase_28 AC 187 ms
108,476 KB
testcase_29 WA -
testcase_30 AC 1,170 ms
128,620 KB
testcase_31 AC 270 ms
123,376 KB
testcase_32 AC 294 ms
123,372 KB
testcase_33 AC 56 ms
64,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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


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


import heapq


def dijkstra(n, G, start=0):
    MINF = -(10**18)
    dist = [MINF] * n
    dist[start] = 0
    pq = []
    heapq.heappush(pq, (0, start))
    visited = [False] * n

    while pq:
        now = heapq.heappop(pq)[1]
        visited[now] = True
        for nxt, cost in G[now]:
            if dist[nxt] < dist[now] + cost and not visited[nxt]:
                dist[nxt] = dist[now] + cost
                heapq.heappush(pq, (dist[now] + cost, nxt))

    return dist


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, A[b] - c))

dist = []
for i in range(N):
    d = dijkstra(N, G, i)
    dist.append(d)

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if dist[0][i] > 0 and dist[i][j] > 0 and dist[j][i] > 0:
            print("inf")
            exit()

print(dist[0][N - 1] + A[0])
0