#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; } rep(i, N) { 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[Q][0] <= T) ans = T; rep(i, N) { rep(j, N) { ll t = d[0][i] + d[j][0] + max(d[i][P] + d[P][j], d[i][Q] + d[Q][j]); if (t <= T) { ans = max(ans, T - max(d[i][P] + d[P][j], d[i][Q] + d[Q][j])); } } } cout << ans << endl; return 0; }