#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) const long long INF = 1LL<<60; vector dijkstra(const vector > > &edges, int s) { int n = edges.size(); vector dist(n, INF); set visited; priority_queue, vector>, greater> > Q; Q.emplace(0, s); while (!Q.empty()) { long long d; int v; if (d > dist[v]) continue; visited.insert(v); if (visited.size() == n) break; tie(d, v) = Q.top(); Q.pop(); dist[v] = d; for (auto &[w, cost] : edges[v]) { if (d + cost < dist[w]) { dist[w] = d + cost; Q.emplace(dist[w], w); } } } return dist; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, p, q, t; cin >> n >> m >> p >> q >> t; --p, --q; vector > > edges(n); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; --a, --b; edges[a].emplace_back(b, c); edges[b].emplace_back(a, c); } vector dp = dijkstra(edges, p); vector dq = dijkstra(edges, q); vector ds = dijkstra(edges, 0); long long ret = -1; for (int i = 0; i < n; i++) { long long tmp; // ずっと一緒 tmp = 2 * ds[i] + dp[i] + dq[i] + dp[q]; if (t >= tmp) ret = t; // 途中で別れる tmp = 2 * ds[i] + 2 * max(dp[i], dq[i]); if (t >= tmp) { ret = max(ret, t - tmp + 2 * ds[i]); } } cout << ret << endl; return 0; }