//dfs(TLE解法) //入力と逆順に探索する #include #include #include using namespace std; using namespace atcoder; using ll = long long; ll N, M, P, Y; vector rest; vector>> G; void dfs(ll pos){ for(ll i = G[pos].size() - 1 ; i >= 0; i--){ auto [to, cost] = G[pos][i]; if(rest[pos] >= cost && rest[pos] - cost > rest[to]){ rest[to] = rest[pos] - cost; dfs(to); } } } int main(){ cin >> N >> M >> P >> Y; G.resize(N + 1); for(int i = 1; i <= M; i++){ ll a, b, c; cin >> a >> b >> c; G[a].push_back({b, c}); G[b].push_back({a, c}); } rest = vector(N + 1, -1); rest[1] = Y; dfs(1); ll ans = 0; for(int i = 1; i <= P; i++){ ll d, e; cin >> d >> e; ans = max(ans, rest[d] / e); } cout << ans << endl; return 0; }