#include<bits/stdc++.h> using namespace std; typedef long long ll; class Dijkstra { public: struct edge { long long v, dist; }; struct state { long long v, cost; bool operator>(const state s) const { return cost > s.cost; } }; const long long INF = (1LL << 60); long long N; vector< vector<edge> > E; Dijkstra(long long n): N(n), E(n) {} //有効グラフの時はこっち。u→vに距離dで結ぶ void add_directed_edge(long long u, long long v, long long d) { E[u].push_back((edge) { v, d }); } //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ void add_undirected_edge(long long u, long long v, long long d) { E[u].push_back((edge) { v, d }); E[v].push_back((edge) { u, d }); } //Sを始点として、他の頂点への最短経路を探す vector<long long> shortest_path(long long S) { vector<long long> dp(E.size(), INF); priority_queue<state, vector<state>, greater<state> > q; q.push((state) { S, 0 }); while(!q.empty()) { long long v = q.top().v, cost = q.top().cost; q.pop(); if(dp[v] <= cost) continue; dp[v] = cost; for(int i=0;i < E[v].size() ; i++) { long long nv = E[v][i].v, ncost = cost + E[v][i].dist; if(dp[nv] > ncost) q.push((state) { nv, ncost }); } } return dp; } }; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m,p,q,t; cin>>n>>m>>p>>q>>t; p--,q--; Dijkstra dij(n); for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; dij.add_undirected_edge(--a,--b,c); } vector<ll> P=dij.shortest_path(p),Q=dij.shortest_path(q),v=dij.shortest_path(0); ll dist = v[p] + P[q] + Q[0]; if(dist<=t){ cout<<t<<endl; return 0; } dist = max(v[p],v[q]); if(2*(dist)>t){ cout<<-1<<endl; return 0; } ll ans=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ dist = v[i] + max(P[i] + P[j],Q[i] + Q[j]) + v[j]; if(dist<=t){ ans = max(ans, t-max(P[i] + P[j],Q[i] + Q[j])); } } } cout<<ans<<endl; }