/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.14 19:43:30 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template struct Dijkstra { private: int V; struct edge { int to; T cost; }; vector> G; public: const T inf = numeric_limits::max(); vector d; Dijkstra(int V) : V(V) { G.resize(V); } void add_edge(int from, int to, T weight, bool directed = false) { G[from].push_back({to,weight}); if (!directed) G[to].push_back({from,weight}); } void build(int s) { d.assign(V, inf); typedef tuple P; priority_queue, greater

> pq; d[s] = 0; pq.push(P(d[s], s)); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = get<1>(p); if (d[v] < get<0>(p)) continue; for (const edge &e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; pq.push(P(d[e.to], e.to)); } } } } }; int main() { int n,m,p,q,t;cin >> n >> m >> p >> q >> t; p--;q--; Dijkstra g1(n),gp(n),gq(n); for (int i = 0; i < m; i++) { int u,v,c;cin >> u >> v >> c; u--;v--; g1.add_edge(u,v,c); gp.add_edge(u,v,c); gq.add_edge(u,v,c); } g1.build(0); gp.build(p); gq.build(q); if (g1.d[p] + gp.d[q] + gq.d[0] <= t) { cout << t << endl; return 0; } ll ans = -1; for (int i = 0; i < n; i++) { ll t1 = g1.d[i]; ll tp = gp.d[i]; ll tq = gq.d[i]; ll aaa = max(tp,tq); if (2 * t1 + 2 * aaa > t) continue; ans = max(ans,t - 2 * aaa); } cout << ans << endl; return 0; }