結果

問題 No.3013 ハチマキ買い星人
ユーザー yamasaKit_
提出日時 2025-01-25 20:41:12
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 95,440 KB
最終ジャッジ日時 2025-01-26 00:08:46
合計ジャッジ時間 52,045 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
import heapq
from itertools import *
from functools import cache, partial
from pprint import pprint
import sys
from typing import Any, Final

try:
    from icecream import ic
except ImportError:  # Graceful fallback if IceCream isn't installed.
    ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a)  # noqa
debug = partial(print, file=sys.stderr)
dpprint = partial(pprint, stream=sys.stderr)
sys.setrecursionlimit(10**6)
MOD = 998244353

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, b = a - 1, b - 1
    G[a].append((c, b))
    G[b].append((c, a))

T = [-1] * N
for _ in range(P):
    d, e = map(int, input().split())
    T[d - 1] = e

s = 0
dist = [float("inf")] * N
dist[s] = 0
used = [False] * N
used[s] = True
queue = []
for e in G[s]:
    heapq.heappush(queue, e)
while queue:
    v_cost, v = heapq.heappop(queue)
    if used[v]:
        continue
    dist[v] = v_cost
    used[v] = True
    for u_cost, u in G[v]:
        if not used[u]:
            heapq.heappush(queue, (v_cost + u_cost, u))

ans = 0
for i in range(N):
    if T[i] == -1:
        continue
    t = T[i]
    dist_ = dist[i]
    ans = max(ans, (Y - dist_) // t)

print(ans)
0