// GPTによるBFS #include using namespace std; using ll = long long; // 定数 const ll INF = 1e18; struct Edge { int to; ll cost; }; int main() { // 入力 int N, M, P; ll Y; cin >> N >> M >> P >> Y; vector> graph(N + 1); for (int i = 0; i < M; i++) { int A, B; ll C; cin >> A >> B >> C; graph[A].push_back({B, C}); graph[B].push_back({A, C}); } vector D(P), E(P); for (int i = 0; i < P; i++) { cin >> D[i] >> E[i]; } // BFSで最短距離を計算 vector minCost(N + 1, INF); minCost[1] = 0; priority_queue, vector>, greater<>> pq; pq.push({0, 1}); while (!pq.empty()) { auto [currentCost, u] = pq.top(); pq.pop(); if (currentCost > minCost[u]) continue; for (const auto &edge : graph[u]) { int v = edge.to; ll nextCost = max(0LL, currentCost + edge.cost); if (nextCost < minCost[v]) { minCost[v] = nextCost; pq.push({nextCost, v}); } } } // パチマキの購入計算 ll maxHachimaki = 0; for (int i = 0; i < P; i++) { int city = D[i]; ll price = E[i]; if (minCost[city] <= Y) { maxHachimaki = max(maxHachimaki, (Y - minCost[city]) / price); } } // 出力 cout << maxHachimaki << endl; return 0; }