#include #include #define space " " #define big 2000000000000000000 using namespace std; using ll = long long; class weighted_graph{ private: public: //vector _node; ll _node; vector>> _e;//pair: void add_edge(ll a,ll b,ll cost){ _e[a].push_back(make_pair(b,cost)); _e[b].push_back(make_pair(a,cost)); } void add_directed_edge(ll from,ll to,ll cost){ _e[from].push_back(make_pair(to,cost)); } vector dijkstra(ll start){ priority_queue,vector>,greater>> pq; pq.push(make_pair(0,start)); vector cost(_node,big); cost[0]=0; while(pq.size()>0){ ll priority,cur; tie(priority,cur) = pq.top(); pq.pop(); if(cost[cur] i: if(cost[cur]+i.second < cost[i.first]){ cost[i.first]=cost[cur]+i.second; pq.push(make_pair(cost[cur]+i.second,i.first)); } } } return cost; } weighted_graph(ll node_count){ //_node = vector(n); _node = node_count; _e = vector>>(node_count); } }; int main(){ ll n,m,p,y; cin >> n >> m >> p >> y; weighted_graph g(n); for(ll i = 0;i> a >> b >> c; a--;b--; g.add_edge(a,b,c); } auto cost = g.dijkstra(0); ll ans = 0; for(ll i = 0;i> d >> e; d--; ans = max(ans,max((ll)0,y-cost[d])/e); } cout << ans << endl; }