#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; struct edge { int v; ll w; }; vector distance(const vector> &g, int s) { const int n = g.size(); priority_queue> q; q.emplace(0, s); vector dist(n, 1e18); dist[s] = 0; while (!q.empty()) { int u = q.top().second; ll d = -q.top().first; q.pop(); if (dist[u] < d) continue; for (edge e : g[u]) { if (dist[e.v] > dist[u] + e.w) { dist[e.v] = dist[u] + e.w; q.emplace(-dist[e.v], e.v); } } } return dist; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M, P, Q; ll T; cin >> N >> M >> P >> Q >> T; P--; Q--; vector> g(N); rep(i, M) { int a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back((edge){b, c}); g[b].push_back((edge){a, c}); } vector distP = distance(g, P); vector distQ = distance(g, Q); vector dist0 = distance(g, 0); ll ans = -1; if (dist0[P] + distP[Q] + distQ[0] <= T) { ans = max(ans, T); } rep(i, N) { if (dist0[i]*2 + max(distP[i]*2, distQ[i]*2) <= T) { ans = max(ans, T - max(distP[i]*2, distQ[i]*2)); } } cout << ans << endl; }