結果
問題 | No.2712 Play more! |
ユーザー |
|
提出日時 | 2024-03-31 19:07:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 491 ms / 2,000 ms |
コード長 | 1,172 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 78,040 KB |
最終ジャッジ日時 | 2024-09-30 23:52:58 |
合計ジャッジ時間 | 6,264 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
# 標準入力された値を整数に変換するdef INT():return int(input())# 標準入力された複数の値を整数に変換するdef MI():return map(int, input().split())# 標準入力された複数の値を整数のリストに変換するdef LI():return list(map(int, input().split()))N, M = MI()A = LI()G = [[] for i in range(N)]for _ in range(M):a, b, c = MI()a -= 1b -= 1G[a].append((b, c - A[b]))MINF = 10**18dist = [MINF] * Ndist[0] = -A[0]exist_negative_cycle = Falsefor i in range(N):update = Falsefor u in range(N):if dist[u] == MINF:continuefor v, c in G[u]:if dist[v] > dist[u] + c:dist[v] = dist[u] + cupdate = Trueif not update:breakif i == N - 1 and update:exist_negative_cycle = Truefor i in range(N):for u in range(N):if dist[u] == MINF:continuefor v, c in G[u]:threshold = dist[u] + cif threshold < dist[v]:dist[v] = -MINFans = -dist[N - 1]print(ans if dist[N - 1] != -MINF else "inf")