#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include #include using namespace atcoder; using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define ll long long #define bigmod 1000000007 #define P pair #define T tuple #define nall(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend()//逆順ソート #define inf 2000000000000000000LL #define mint modint998244353 #define mkp make_pair #define mkt make_tuple template using priority_minq = priority_queue, greater>;//小さい順 ll min(ll a1,ll b1){if(a1>b1)return b1;else return a1;} ll max(ll a1,ll b1){if(a1>b1)return a1;else return b1;} #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) //cout << fixed << setprecision(10); double型出力するときに使うやつ ll n,m,p,y; vector

g[200009];//to,cost ll dat[200009]; int main(){ cin >> n >> m >> p >> y; rep(i,m){ ll a,b,c; cin >> a >> b >> c; g[a].push_back(mkp(b,c)); g[b].push_back(mkp(a,c)); } rep(i,n)dat[i+1] = 0; dat[1] = y; priority_queue

qu; qu.push(mkp(y,1)); while(!qu.empty()){ ll to,cost; tie(cost,to) = qu.top(); qu.pop(); if(cost < dat[to])continue; for(auto nex : g[to]){ if(dat[nex.first] < cost - nex.second){ dat[nex.first] = cost - nex.second; qu.push(mkp(dat[nex.first],nex.first)); } } } ll ans = 0; rep(i,p){ ll pos,cost; cin >> pos >> cost; chmax(ans,dat[pos]/cost); } cout << ans << endl; }