#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include #include using namespace atcoder; using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define all(v) v.begin(),v.end() const ll INF = (ll)2e18; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N, M, P, Y; cin >> N >> M >> P >> Y; ll ans = 0; vector A(M), B(M), C(M); vector>> G(N); rep(i,M){ cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--; G[A[i]].push_back({B[i], C[i]}); G[B[i]].push_back({A[i], C[i]}); } unordered_map memo; vector valid(N, false); vector D(P), E(P); rep(i,P){ cin >> D[i] >> E[i]; D[i]--; valid[D[i]] = true; memo[D[i]] = E[i]; } vector dist(N, INF); dist[0] = 0; priority_queue, vector>, greater>> pq; pq.push({0, 0}); while(!pq.empty()){ ll now = pq.top().second; ll d = pq.top().first; pq.pop(); for(auto [next,c]:G[now]){ if(dist[next]>dist[now]+c){ dist[next] = dist[now] + c; pq.push({dist[next], next}); } } } rep(i,N){ if(dist[i]>=Y||!valid[i]){ continue; } ans = max(ans, (Y - dist[i]) / memo[i]); } cout << ans << endl; }