結果
問題 |
No.2712 Play more!
|
ユーザー |
|
提出日時 | 2024-03-31 15:29:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,242 bytes |
コンパイル時間 | 435 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 130,512 KB |
最終ジャッジ日時 | 2024-09-30 20:46:24 |
合計ジャッジ時間 | 16,395 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 7 TLE * 1 |
ソースコード
# 標準入力された値を整数に変換する 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] = A[start] 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])