#include using namespace std; typedef pair pii; typedef long long ll; typedef vector vi; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i,n) rep2(i,0,n) #define rep2(i,m,n) for(int i=m;i<(n);i++) #define ALL(c) (c).begin(),(c).end() #define dump(x) cout << #x << " = " << (x) << endl constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } template ostream& operator<<(ostream& os, const pair& p) { os<<"("< ostream& operator<<(ostream& os, const vector& v) { os<<"{"; rep(i, v.size()) { if (i) os<<","; os< g[maxn]; ll d[maxn][maxn]; int main() { int N, M, P, Q, T; cin >> N >> M >> P >> Q >> T; --P; --Q; rep(i, M) { int a, b, c; cin >> a >> b >> c; --a; --b; g[a].eb(b, c); g[b].eb(a, c); } rep(i, N) { rep(j, N) d[i][j] = INF; d[i][i] = 0; } vector cand; cand.pb(0); cand.pb(P); cand.pb(Q); for (int i : cand) { using Data = pair; priority_queue, greater> que; que.push(mp(0ll, i)); while (!que.empty()) { auto t = que.top(); que.pop(); int v = t.se; if (t.fi > d[i][v]) continue; for (pii e : g[v]) { if (d[i][e.fi] > d[i][v] + e.se) { d[i][e.fi] = d[i][v] + e.se; que.push(mp(d[i][e.fi], e.fi)); } } } } int ans = -1; if (d[0][P] + d[P][Q] + d[0][Q] <= T) ans = T; rep(i, N) { rep(j, N) { ll t = d[0][i] + d[0][j] + max(d[P][i] + d[P][j], d[Q][i] + d[Q][j]); if (t <= T) { ans = max(ans, T - max(d[P][i] + d[P][j], d[Q][i] + d[Q][j])); } } } cout << ans << endl; return 0; }