#GPT_25/1/3 from heapq import heappush, heappop from collections import defaultdict import sys input = sys.stdin.read def main(): data = input().split() idx = 0 # 入力処理 N, M, P, Y = map(int, data[idx:idx+4]) idx += 4 graph = defaultdict(list) for _ in range(M): A, B, C = map(int, data[idx:idx+3]) idx += 3 graph[A].append((B, C)) graph[B].append((A, C)) shops = [] for _ in range(P): D, E = map(int, data[idx:idx+2]) idx += 2 shops.append((D, E)) # Dijkstra法 def dijkstra(start): dist = [float('inf')] * (N + 1) dist[start] = 0 pq = [(0, start)] # (コスト, ノード) while pq: current_cost, current_node = heappop(pq) if current_cost > dist[current_node]: continue for neighbor, cost in graph[current_node]: new_cost = current_cost + cost if new_cost < dist[neighbor]: dist[neighbor] = new_cost heappush(pq, (new_cost, neighbor)) return dist # 最短距離計算 min_cost = dijkstra(1) # 各店における最大の鉢巻数を計算 max_hachimaki = 0 for D, E in shops: if min_cost[D] <= Y: max_hachimaki = max((Y - min_cost[D]) // E, max_hachimaki) # 結果出力 print(max_hachimaki) if __name__ == "__main__": main()