結果

問題 No.3013 ハチマキ買い星人
ユーザー anonymously
提出日時 2025-01-25 13:57:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,229 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 144,428 KB
最終ジャッジ日時 2025-01-25 23:03:54
合計ジャッジ時間 25,478 ms
ジャッジサーバーID
(参考情報)
judge1 / judge9
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappush, heappop
N, M, P, Y = map(int, input().split())
graph = [{} for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c
headband = [None for _ in range(N)]
for _ in range(P):
    d, e = map(int, input().split())
    d -= 1
    headband[d] = e

cost = [float('inf') for _ in range(N)]
cost[0] = 0
Q = [(0, 0)]
heapify(Q)

maximum = 0
while Q:
    c, v = heappop(Q)
    if c > cost[v]:
        continue
    if headband[v]:
        maximum = max(maximum, max(Y - cost[v], 0) // headband[v])
    for u in graph[v]:
        d = c + graph[v][u]
        if d < cost[u]:
            cost[u] = d
            heappush(Q, (d, u))
print(maximum)
0