#include <bits/stdc++.h> using namespace std; typedef pair<int64_t, int64_t> P; const int64_t INF = 1e18; vector<int64_t> dijkstra(int N, int s, vector<P> edges[]){ vector<int64_t> dist(N, INF); dist[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push({0, s}); while(que.size()){ auto p = que.top(); que.pop(); int i = p.second; int64_t d = p.first; if(d > dist[i]) continue; for(auto& e : edges[i]){ int j = e.first; int64_t d2 = d + e.second; if(d2 < dist[j]){ dist[j] = d2; que.push({d2, j}); } } } return dist; } int main(){ int N, M, A, B, T; cin >> N >> M >> A >> B >> T; A--; B--; vector<P> edges[2000]; for(int i=0; i<M; i++){ int a, b, c; cin >> a >> b >> c; edges[a-1].push_back({b-1, c}); edges[b-1].push_back({a-1, c}); } auto D0 = dijkstra(N, 0, edges); auto DA = dijkstra(N, A, edges); auto DB = dijkstra(N, B, edges); if(D0[A] + D0[B] + DA[B] <= T){ cout << T << endl; return 0; } int64_t ans = -1; for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ int64_t a = D0[i], b = max(DA[i]+DA[j], DB[i]+DB[j]), c = D0[j]; if(a+b+c <= T){ ans = max(ans, T-b); } } } cout << ans << endl; return 0; }