#include #include #include using namespace std; // #include // using namespace atcoder; // using mint = modint998244353; using ll = long long; #define fix(x) fixed << setprecision(x) #define rep(i, n) for(int i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n >> m >> p >> y; vector> g(n); rep(i,m){ int a,b,c; cin >> a >> b >> c; --a; --b; g[a].emplace_back(b,c); g[b].emplace_back(a,c); } vector x(n,INFLL), dist(n,INFLL); rep(i,p){ int d,e; cin >> d >> e; x[d-1] = e; } using P = pair; priority_queue,greater

> pq; pq.emplace(0,0); dist[0] = 0; while(pq.size()){ auto [d,now] = pq.top(); pq.pop(); if(dist[now]!=d) continue; for(auto [to,c]:g[now]){ if(chmin(dist[to],d+c)) pq.emplace(d+c,to); } } ll ans = 0; rep(i,n) chmax(ans, (y-dist[i])/x[i]); cout << ans << '\n'; return 0; }