#include #include using namespace std; using ll = long long; using ull = unsigned long long; using mint = atcoder::modint998244353; using maxt = atcoder::modint1000000007; //ここからグラフ探索系 using Graph = vector>; struct edge { int to; ll cost; }; using Cost_Graph = vector>; using D_heap = priority_queue, vector>, greater>>; //グラフ探索系終わり vector Era(int N) { vector ans(0, 0); vector isprime(N + 1, true); isprime.at(1) = false; for(int i = 1; i <= N; i++) { if(isprime.at(i)) { ans.push_back(i); for(int j = 2 * i; j <= N; j += i) { isprime.at(j) = false; } } } return ans; } ll POW(ll a, int N) { if(N == 0) { return 1; } if(N == 1) { return a; } ll ans = POW(a, N / 2) * POW(a, N / 2); if(N % 2 == 1) { ans *= a; } return ans; } ll GCD(ll a, ll b) { if(b == 0) { return a; } int r = a % b; return GCD(b, r); } ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); } vector zaatu(vector a) { vector b(0, 0); b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); int s = b.size(); for(ll &o : a) { int l = 0, r = s, c = 0; while(r - l > 1) { c = (l + r) / 2; if(b.at(c) <= o) { l = c; } else { r = c; } } o = r; } return a; } struct FenwickTree { int N; vector a; FenwickTree(int n) { N = n; a.assign(N + 1, 0); } void add(int i, ll x) { for(int j = i; j <= N; j += (j & -j)) { a.at(j) += x; } } ll sum(int i, int j) { return sum_sub(j) - sum_sub(i - 1); } ll sum_sub(int i) { if(i == 0) { return 0; } ll s = 0; for(int j = i; j > 0; j -= (j & -j)) { s += a.at(j); } return s; } }; ll tento(vector a) { int s = a.size(); FenwickTree tmp(s); ll ans = 0; for(int i = 0; i < s; i++) { ans += i - tmp.sum_sub(a.at(i)); tmp.add(a.at(i), 1); } return ans; } //__builtin_popcount //next_permutation //srand((unsigned)time(NULL)) //cout << fixed << setprecision(Digit); //library end vector dist(200010, -1LL); int main() { int N, M, P; ll Y; cin >> N >> M >> P >> Y; Cost_Graph G(N + 1, vector(0)); for(int i = 0; i < M; i++) { int now; edge e; cin >> now >> e.to >> e.cost; G.at(now).push_back(e); } D_heap que; que.push(make_pair(0LL, 1)); while(!que.empty()) { pair v = que.top(); que.pop(); if(dist.at(v.second) != -1LL) { continue; } dist.at(v.second) = v.first; for(edge next_v : G.at(v.second)) { if(dist.at(next_v.to) == -1LL) { que.push(make_pair(v.first + next_v.cost, next_v.to)); } } } ll ans = 0; for(int i = 0; i < P; i++) { int D; ll E; cin >> D >> E; if(dist.at(D) != -1LL && dist.at(D) <= Y) { ans = max(ans, (Y - dist.at(D)) / E); } } cout << ans << endl; }