結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2022-06-01 21:35:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,026 bytes |
コンパイル時間 | 153 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 79,764 KB |
最終ジャッジ日時 | 2024-09-21 01:44:17 |
合計ジャッジ時間 | 5,720 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 36 WA * 4 |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') N = int(input()) C = int(input()) V = int(input()) S = list(map(int, input().split())) T = list(map(int, input().split())) Y = list(map(int, input().split())) M = list(map(int, input().split())) INF = 1 << 30 E = [[] for _ in range(N + 1)] for s, t, y, m in zip(S, T, Y, M): E[s].append((t, y, m)) E[t].append((s, y, m)) # t[i][j] := 町iに総コストjかけて辿り着ける最小の時間 dp = [[INF for _ in range(C + 1)] for _ in range(N + 1)] dp[1][0] = 0 h = [(0, 1, 0)] while len(h) > 0: _, v, c = heapq.heappop(h) for d, y, m in E[v]: if c + y > C: continue if dp[d][c + y] > dp[v][c] + m: dp[d][c + y] = dp[v][c] + m heapq.heappush(h, (dp[d][c + y], d, c + y)) ans = min(dp[N]) print(ans if ans < INF else -1)