/* import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); long y = sc.nextLong(); Dijkstra djk = new Dijkstra(n); long[] t = new long[n + 1]; for(int i = 1;i <= n;i++) { t[i] = Long.MAX_VALUE; } for(int i = 0;i < m;i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); djk.addLine(a, b, c); djk.addLine(b, a, c); }for(int i = 0;i < p;i++) { int d = sc.nextInt(); t[d] = sc.nextLong(); } djk.solve(1,0); long ans = 0; for(int i = 1;i <= n;i++) { long comp = Math.max(0, y - djk.min[i])/t[i]; ans = Math.max(ans, comp); }System.out.print(ans); }public static class Dijkstra { public PriorityQueue q = new PriorityQueue<>(); public long[] min; public boolean[] vis; public HashMap> nextNode = new HashMap<>(); public int n; public Dijkstra(int n) { this.n = n; min = new long[n + 1]; vis = new boolean[n + 1]; for(int i = 1;i <= n;i++) { min[i] = Long.MAX_VALUE/2; nextNode.put(i, new HashSet<>()); } }public void addLine(int from,int to,long cost) { nextNode.get(from).add(new Pair(cost,to)); } public void solve(int ind,long val) { min[ind] = val; q.add(new Pair(val,ind)); while(!q.isEmpty()) { Pair p = q.poll(); if(vis[p.x])continue; vis[p.x] = true; for(Pair s:nextNode.get(p.x)) { if(min[s.x] > min[p.x] + s.v) { min[s.x] = min[p.x] + s.v; q.add(new Pair(min[s.x],s.x)); } } } }public long getMin(int a) { return min[a]; } public static class Pair implements Comparable { long v; int x; public Pair(long a,int b) { v = a; x = b; }public int compareTo(Pair p) { if(this.v < p.v) { return -1; }if(this.v > p.v) { return 1; }return 0; }public boolean equals(Object o) { Pair p = (Pair)o; return p.x == this.x && p.v == this.v; } } } } */ #include #include #include #include #include #include using namespace std; class Dijkstra { public: struct Pair { long long v; int x; Pair(long long a, int b) : v(a), x(b) {} bool operator<(const Pair &p) const { return v > p.v; // Reverse for min-heap } }; vector min; vector vis; map> nextNode; int n; Dijkstra(int n) : n(n), min(n + 1, LLONG_MAX / 2), vis(n + 1, false) {} void addLine(int from, int to, long long cost) { nextNode[from].insert(Pair(cost, to)); } void solve(int ind, long long val) { priority_queue q; min[ind] = val; q.push(Pair(val, ind)); while (!q.empty()) { Pair p = q.top(); q.pop(); if (vis[p.x]) continue; vis[p.x] = true; for (const Pair &s : nextNode[p.x]) { if (min[s.x] > min[p.x] + s.v) { min[s.x] = min[p.x] + s.v; q.push(Pair(min[s.x], s.x)); } } } } }; int main() { int n, m, p; long long y; cin >> n >> m >> p >> y; Dijkstra djk(n); vector t(n + 1, LLONG_MAX); for (int i = 0; i < m; i++) { int a, b; long long c; cin >> a >> b >> c; djk.addLine(a, b, c); djk.addLine(b, a, c); } for (int i = 0; i < p; i++) { int d; cin >> d; cin >> t[d]; } djk.solve(1, 0); long long ans = 0; for (int i = 1; i <= n; i++) { if (t[i] != LLONG_MAX) { long long comp = max(0LL, (y - djk.min[i]) / t[i]); ans = max(ans, comp); } } cout << ans << endl; return 0; }