#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; void dijkstra(ll start, vector>>& graph, vector& dist) { dist[start] = 0; priority_queue, vector>, greater>> pq; vector used(dist.size(), false); pq.push(make_pair(0, start)); while (!pq.empty()) { ll d, node; tie(d, node) = pq.top(); pq.pop(); if (used[node]) continue; used[node] = true; for (pair element : graph[node]) { ll new_d, new_node; tie(new_node, new_d) = element; new_d += d; if (new_d < dist[new_node]) { dist[new_node] = new_d; pq.push(make_pair(dist[new_node], new_node)); } } } } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n, m, p, q, t; scanf("%lld %lld %lld %lld %lld", &n, &m, &p, &q, &t); p--; q--; vector>> g(n); for (ll i = 0; i < m; i++) { ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c); a--; b--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } vector d0(n, INF), dp(n, INF), dq(n, INF); dijkstra(0, g, d0); dijkstra(p, g, dp); dijkstra(q, g, dq); ll res = 0; if (d0[p] + dp[q] + dq[0] <= t) printf("%lld\n", t); else if (max(d0[p] + dp[0], d0[q] + dq[0]) > t) puts("-1"); else { for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { ll tmp = max(d0[i] + dp[i] + dp[j] + d0[j], d0[i] + dq[i] + dq[j] + d0[j]); if (tmp > t) continue; chmax(res, d0[i] + d0[j] + t - tmp); } } printf("%lld\n",res); } return 0; }