#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; using i32 = int32_t; template void init_n(vector& v, size_t n, U x) { v = vector(n, x); } template void init_n(vector& v, size_t n) { init_n(v, n, T()); } template void read_n(vector& v, size_t n, size_t o = 0) { v = vector(n+o); for (size_t i=o; i> v[i]; } template void read_n(T a[], size_t n, size_t o = 0) { for (size_t i=o; i> a[i]; } template T gabs(const T& x) { return max(x, -x); } #define abs gabs template vector djk(const T& e, i64 n, i64 s) { vector d(n + 1, 1e18); vector fix(n + 1); using P = pair; priority_queue, greater

> pq; d[s] = 0; pq.emplace(0, s); while (!pq.empty()) { P p = pq.top(); pq.pop(); i64 u = p.second; if (fix[u]) continue; fix[u] = true; for (const P& q : e[u]) { i64 cv = q.first, v = q.second; if (!fix[v] && d[u] + cv < d[v]) { pq.emplace(d[u] + cv, v); d[v] = d[u] + cv; } } } return d; } i64 n, m, p, q, t; vector>> g; int main() { cin >> n >> m >> p >> q >> t; init_n(g, n + 1); for (i64 i = 0; i < m; ++i) { i64 a, b, c; cin >> a >> b >> c; g[a].emplace_back(c, b); g[b].emplace_back(c, a); } auto d1 = djk(g, n, 1); auto dp = djk(g, n, p); auto dq = djk(g, n, q); bool ok = false; i64 ans = 0; if (d1[p] + dp[q] + dq[1] <= t) { ans = t; ok = true; } for (i64 u = 1; u <= n; ++u) { for (i64 v = 1; v <= n; ++v) { i64 x = max(dp[u] + dp[v], dq[u] + dq[v]); if (d1[u] + d1[v] + x <= t) { ans = max(ans, t - x); ok = true; } } } if (!ok) ans = -1; cout << ans << endl; return 0; }