#include using namespace std; #define rep(i, s, t) for (auto i{s}; i < t; ++i) typedef long long ll; template bool chmin(T &a, T const &x) { return x < a ? a = x, true : false; } template bool chmax(T &a, T const &x) { return x > a ? a = x, true : false; } int main() { ll N, M, P, Y; cin >> N >> M >> P >> Y; vector G(N, vector>{}); vector C(N, 1<<30); rep(_, 0, M) { int a, b, c; cin >> a >> b >> c; --a; --b; G[a].emplace_back(b, c); G[b].emplace_back(a, c); } rep(_, 0, P) { int d, e; cin >> d >> e; --d; C[d] = e; } constexpr ll inf{(1LL << 62) - 1}; vector D(N, inf); priority_queue pq(greater{}, vector>{}); D[0] = 0; pq.emplace(0, 0); while (!pq.empty()) { auto const [d, u] = pq.top(); pq.pop(); if (D[u] < d) continue; for (auto const &[v, c] : G[u]) if (chmin(D[v], d+c)) pq.emplace(d+c, v); } ll ans{0}; rep(i, 0, N) chmax(ans, (Y - D[i]) / C[i]); cout << ans << endl; }