#include #include #include #include #include #include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; #define rep(i, n) for (int i = 0; i< (int)(n); i++) using node = pair; ll inf = 4e18; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, p; ll y; cin >> n >> m >> p >> y; map> adj; map, ll> edges; rep(i, m){ int a, b; ll c; cin >> a >> b >> c; adj[a].insert(b); adj[b].insert(a); edges[{a, b}] = c; edges[{b, a}] = c; } vector dist(n+1, inf); dist[1] = 0; priority_queue, greater> pq; pq.push({0, 1}); while(!pq.empty()){ node u = pq.top(); pq.pop(); if(u.first > dist[u.second])continue; for(auto v : adj[u.second]){ ll alt = dist[u.second] + edges[{u.second, v}]; if(alt < dist[v]){ dist[v] = alt; pq.push({alt, v}); } } } ll ans = 0; rep(i, p){ int d; ll e; cin >> d >> e; if(dist[d] == inf)continue; if(dist[d] >= y)continue; ans = max(ans, (y-dist[d])/e); } cout << ans << endl; return 0; }