#include 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 > 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 shortest_path(long long S) { vector dp(E.size(), INF); priority_queue, greater > 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>a>>b>>c; dij.add_undirected_edge(--a,--b,c); } vector 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){ cout<<-1<