#include #include using mint = atcoder::static_modint<998244353>; // using mint = atcoder::static_modint<1000000007>; using namespace std; using namespace atcoder; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i dx{1,0,-1,0},dy{0,1,0,-1}; struct dijkstra{ public: dijkstra():_n(0){} dijkstra(int n):_n(n),G(n){} void add_edge(int from,int to,ll d){ G[from].push_back({to,d}); } vector start_from(int start){ vector dist(_n,-1); priority_queue,vector>,greater>> Q; Q.push({0,start}); dist[start]=0; while(!Q.empty()){ auto p=Q.top(); Q.pop(); int now=p.second; ll d=p.first; if(d!=dist[now])continue; for(auto e:G[now]){ int to=e.first; ll w=e.second; if(dist[to]==-1 || w+d>> G; }; int main(){ ll n,m,p,y;cin >> n >> m >> p >> y; dijkstra G(n); rep(i,0,m){ int a,b;cin >> a >> b; ll c;cin >> c; a--,b--; G.add_edge(a,b,c); swap(a,b); G.add_edge(a,b,c); } auto dist=G.start_from(0); ll ans=0; rep(i,0,p){ ll d,e;cin >> d >> e; d--; ans=max(ans,max(0LL,y-dist[d])/e); } cout << ans; }