#include using namespace std; using ll = long long; #define int ll #undef INT_MAX #define INT_MAX LLONG_MAX using xy = array; signed main() { int n, m, p, y; cin >> n >> m >> p >> y; vector r(n, INT_MAX); vector> v(n, vector(0)); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; --a; --b; v[a].push_back({b, c}); v[b].push_back({a, c}); } for (int i = 0; i < p; i++) { int a, b; cin >> a >> b; --a; r[a] = min(r[a], b); } priority_queue, greater> q; q.push({0, 0}); vector dist(n, INT_MAX); while (!q.empty()) { auto [c, f] = q.top(); q.pop(); dist[f] = c; for (auto [k, d] : v[f]) { if (dist[k] == INT_MAX) { q.push({c+d, k}); } } while (!q.empty() && dist[q.top()[1]] != INT_MAX) q.pop(); } int ans = 0; for (int i = 0; i < n; i++) { if (r[i] == INT_MAX) continue; ans = max(ans, (y - dist[i]) / r[i]); } cout << ans << endl; }