#include using namespace std; using ll = long long; using T = tuple; ll Y; bool operator<(T& t1, T& t2) { return (Y - get<0>(t1)) * get<1>(t2) < (Y - get<0>(t2)) * get<1>(t1); } int main() { int N, M, P; cin >> N >> M >> P >> Y; vector>> G(N); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } map mp; for (int i = 0; i < P; i++) { ll d, e; cin >> d >> e; mp[d - 1] = e; } // (cost, e, to)を乗せる // cost/eの最大化 // (Y-cost1)*e2<(Y-cost2)*e1 ll ans{}; priority_queue que; if (!mp.contains(0)) que.push({0, 1000000000, 0}); else que.push({0, mp[0], 0}); vector dist(N); while (!que.empty()) { auto [c, e, now] = que.top(); que.pop(); ans = max(ans, (Y - c) / e); for (auto&& [p, c2] : G[now]) { if (c + c2 > Y) continue; auto e2 = e; if (mp.contains(p)) e2 = mp[p]; T t2{c + c2, e2, p}; if (dist[p] > (c + c2) / e2) continue; que.push({t2}); } } cout << ans << endl; }