#include #include using namespace std; using namespace atcoder; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = (int)(n - 1); i >= 0; i--) template bool chmax(T &a,const T &b){if(a bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;} using ll = long long; #define int ll using vi = vector; using vvi = vector>; using vb = vector; using vvb = vector>; using vs = vector; using pii = pair; /* using mint = modint; using vm = vector; using vvm = vector>; */ signed main(){ const int inf = 1ll << 60; int n, m, p, y; cin >> n >> m >> p >> y; vector g(n, vector(0)); while(m--){ int a, b, c; cin >> a >> b >> c; a--; b--; g.at(a).emplace_back(b, c); g.at(b).emplace_back(a, c); } vi shop(n, -1); while(p--){ int place, price; cin >> place >> price; place--; shop.at(place) = price; } int ans = 0; priority_queue, greater<>> dijk; dijk.emplace(0, 0); vi d(n, inf); d.at(0) = 0; while(!dijk.empty()){ auto [cost, from] = dijk.top(); dijk.pop(); if(cost > d.at(from)) continue; for(auto &[to, c] : g.at(from)){ if(cost + c >= y) continue; if(!chmin(d.at(to), cost + c)) continue; dijk.emplace(cost + c, to); } } rep(i, n) if(shop.at(i) != -1) chmax(ans, (y - d.at(i)) / shop.at(i)); cout << ans << endl; }