using System; using System.Collections.Generic; using System.Linq; class Edge { public Edge(int f, int n, int c) { From = f; Next = n; Cost = c; } public int From = 0; public int Next = 0; public int Cost = 0; } class Program { static void Main() { long N, M, P, Y; { long[] vs = Console.ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); N = vs[0]; M = vs[1]; P = vs[2]; Y = vs[3]; } List[] lists = new List[N]; for (int i = 0; i < N; i++) lists[i] = new List(); for (int i = 0; i < M; i++) { int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); int a = vs[0] - 1; int b = vs[1] - 1; int c = vs[2]; lists[a].Add(new Edge(a, b, c)); lists[b].Add(new Edge(b, a, c)); } long[] costs = new long[N]; for (int i = 0; i < N; i++) costs[i] = long.MaxValue; costs[0] = 0; Queue q = new Queue(); q.Enqueue(0); while (q.Count > 0) { int cur = q.Dequeue(); long cost = costs[cur]; foreach (Edge edge in lists[cur]) { long ncost = cost + edge.Cost; int next = edge.Next; if (costs[next] > ncost) { costs[next] = ncost; q.Enqueue(next); } } } long ans = 0; for (int i = 0; i < P; i++) { int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); int a = vs[0] - 1; int c = vs[1]; if (Y - costs[a] > 0) ans = Math.Max(ans, (Y - costs[a]) / c); } Console.WriteLine(ans); } }