結果

問題 No.3013 ハチマキ買い星人
ユーザー miya145592
提出日時 2025-01-25 15:03:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 755 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 121,160 KB
最終ジャッジ日時 2025-01-25 23:40:12
合計ジャッジ時間 17,162 ms
ジャッジサーバーID
(参考情報)
judge5 / judge13
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

INF = 10 ** 18

def dijkstra(s, N): # (始点, ノード数)
    dist = [INF for _ in range(N)]
    hq = [(0, s)]
    dist[s] = 0
    seen = [False] * N # ノードが確定済みかどうか
    while hq:
        d, v = heappop(hq) # ノードを pop する
        if seen[v]:
            continue
        seen[v] = True
        for to, cost in G[v]: # ノード v に隣接しているノードに対して
            if dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

import sys
input = sys.stdin.readline
N, M, P, Y = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a-=1
    b-=1
    G[a].append((b, c))
    G[b].append((a, c))
D = dict()
for _ in range(P):
    d, e = map(int, input().split())
    d-=1
    D[d] = e

cost = dijkstra(0, N)
ans = 0
for i in range(N):
    if i not in D:
        continue
    if Y-cost[i]<=0:
        continue
    ans = max(ans, (Y-cost[i])//D[i])
print(ans)
0