#include #include using namespace std; using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } struct Edge { long long to; long long cost; }; using Graph = vector>; using P = pair; const long long INF = 1LL << 60; /* dijkstra(G,s,dis) 入力:グラフ G, 開始点 s, 距離を格納する dis 計算量:O(|E|log|V|) 副作用:dis が書き換えられる */ void dijkstra(const Graph &G, int s, vector &dis) { int N = G.size(); dis.resize(N, INF); priority_queue, greater

> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ dis[s] = 0; pq.emplace(dis[s], s); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = p.second; if (dis[v] < p.first) { // 最短距離で無ければ無視 continue; } for (auto &e : G[v]) { if (dis[e.to] > dis[v] + e.cost) { // 最短距離候補なら priority_queue に追加 dis[e.to] = dis[v] + e.cost; pq.emplace(dis[e.to], e.to); } } } } int main() { long long N,M,P,Y; cin >> N >> M >> P >> Y; Graph G(N); rep(i,M){ long long a,b,c; cin >> a >> b >> c; a--; b--; G[a].push_back({b,c}); G[b].push_back({a,c}); } vector dis; dijkstra(G,0,dis); // rep(i,N){ // cout << dis[i] << endl; // } long long res = 0; rep(i,P){ long long d,e; cin >> d >> e; d--; if(Y - dis[d] > 0)chmax(res,(Y - dis[d]) / e); } cout << res << endl; }