結果
| 問題 |
No.2477 Drifting
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-01 16:13:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,333 bytes |
| コンパイル時間 | 603 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 273,708 KB |
| 最終ジャッジ日時 | 2025-01-01 16:14:22 |
| 合計ジャッジ時間 | 26,278 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 TLE * 7 |
ソースコード
## https://yukicoder.me/problems/no/2477
MAX_INT = 10 ** 18
def main():
N, M = map(int, input().split())
next_nodes = [[] for _ in range(N)]
for _ in range(M):
u, v, w = map(int, input().split())
next_nodes[u - 1].append((v - 1, w))
K = int(input())
state_base_map = {}
for _ in range(K):
a, b, c = map(int, input().split())
a -= 1
b -= 1
c -= 1
if (a, b) not in state_base_map:
state_base_map[(a, b)] = {}
state_base_map[(a, b)][c] = 1
dp = [{} for _ in range(N)]
dp[0][-1] = 0
for s_n in range(N):
for prev_, cost in dp[s_n].items():
forbiddens = {}
if (prev_, s_n) in state_base_map:
forbiddens = state_base_map[(prev_, s_n)]
for next_n, w in next_nodes[s_n]:
if next_n in forbiddens:
continue
new_cost = w + cost
if s_n not in dp[next_n]:
dp[next_n][s_n] = MAX_INT
dp[next_n][s_n] = min(dp[next_n][s_n], new_cost)
answer = MAX_INT
for cost in dp[-1].values():
answer = min(answer, cost)
if answer == MAX_INT:
print(-1)
else:
print(answer)
if __name__ == "__main__":
main()