#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int MAX_N = 2010; ll INF = 1LL<<60; vector> G(MAX_N); void dijkstra(int s,vector& dist) { priority_queue,greater

> que; dist[s] = 0; que.push(P(0,s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (dist[v] < p.first) continue; for (int i = 0;i < G[v].size();++i) { P e = G[v][i]; if (dist[e.first] > dist[v]+e.second) { dist[e.first] = dist[v]+e.second; que.push(P(dist[e.first],e.first)); } } } } int main() { int n,m,p,q,t; cin >> n >> m >> p >> q >> t; for (int i = 0;i < m;++i) { int u,v,w; cin >> u >> v >> w; u--;v--; G[u].push_back(P(v,w)); G[v].push_back(P(u,w)); } p--;q--; vector dist1(n,INF),dist2(n,INF),dist3(n,INF); dijkstra(0,dist1); dijkstra(p,dist2); dijkstra(q,dist3); if (dist1[p]*2 > t || dist1[q]*2 > t) { cout << -1 << endl; return 0; } if (dist1[p]+dist2[q]+dist3[0] <= t) { cout << t << endl; return 0; } ll ans = 0; for (int i = 0;i < n;++i) { for (int j = 0;j < n;++j) { ll d = max(dist2[i],dist3[i])+max(dist2[j],dist3[j]); if (d+dist1[i]+dist1[j] > t) continue; ans = max(ans,t-d); } } cout << ans << endl; return 0; }