#include #define rep(i,n) for(int i=0;i ; using Pll = pair; const ll INF = 1e18; const int MOD = 1000000007; ll v = 2005,e; vector>> graph(v,vector>()); vector dijkstra(ll start){ vector shortest(v); vector visited(v,false); priority_queue,vector>,greater>> pq; pq.push(make_pair(0,start)); while (!pq.empty()){ pair now = pq.top(); pq.pop(); ll cost,node; tie(cost,node) = now; if(visited[node]){ continue; }else{ shortest[node] = cost; visited[node] = true; for(pair next:graph[node]){ ll next_cost,next_node; tie(next_cost,next_node) = next; pq.push(make_pair(cost+next_cost,next_node)); } } } return shortest; } int main(){ int p,q; ll time; cin >> v >> e >> p >> q >> time; --p;--q; rep(i,e){ int a,b; ll c; cin >> a >> b >> c; --a;--b; graph[a].push_back(Pll(c,b)); graph[b].push_back(Pll(c,a)); } vector dis_zero = dijkstra(0); vector dis_p = dijkstra(p); vector dis_q = dijkstra(q); if(dis_zero[p] + dis_p[q] + dis_zero[q] <= time){ cout << time << endl; return 0; } ll ans = -1; rep(i,v){ ll s = dis_zero[i]; ll t = dis_p[i]; ll u = dis_q[i]; if(2*(s+t) <= time && 2*(s+u) <= time){ ans = max(ans,time - 2*max(t,u)); } } cout << ans << endl; return 0; }