結果
| 問題 |
No.2477 Drifting
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-08 20:40:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 715 ms / 2,000 ms |
| コード長 | 749 bytes |
| コンパイル時間 | 295 ms |
| コンパイル使用メモリ | 82,300 KB |
| 実行使用メモリ | 146,268 KB |
| 最終ジャッジ日時 | 2024-06-26 13:31:45 |
| 合計ジャッジ時間 | 9,202 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
u, v, w = map(int, input().split())
edges[u - 1].append((v - 1, w))
ng = set()
k = int(input())
for _ in range(k):
a, b, c = map(int, input().split())
a -= 1
b -= 1
c -= 1
ng.add((a, b, c))
cand = [[] for _ in range(n)]
cand[0] = [(0, 0)]
for l in range(n):
cand[l].sort(key=lambda x: x[0])
for d, a in cand[l]:
nex = []
for r, w in edges[l]:
if (a, l, r) in ng:
nex.append((r, w))
else:
cand[r].append((d + w, l))
edges[l] = nex
ans = 1 << 60
for d, _ in cand[n - 1]:
ans = min(ans, d)
if ans == 1 << 60:
print(-1)
else:
print(ans)