#include using namespace std; using ll = long long; using vi = vector; using vll = vector; using vvi = vector>; using vvl = vector>; ll INF = 1010101010101010LL; vector>> ps; struct N { ll i, d; N(int i, ll d) : i(i), d(d) {} }; bool operator<(const N &l, const N &r) { return l.d > r.d; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, m, p, q, t; cin >> n >> m >> p >> q >> t; p--; q--; vector fromp(n, INF), fromq(n, INF), from1(n, INF); ps.resize(n); for (int i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; ps[a].emplace_back(b, c); ps[b].emplace_back(a, c); } priority_queue queue; queue.emplace(p, 0); while (queue.size()) { auto v = queue.top(); queue.pop(); if (fromp[v.i] < INF) continue; fromp[v.i] = v.d; for (auto &path : ps[v.i]) { if (fromp[path.first] < INF) continue; queue.emplace(path.first, v.d + path.second); } } queue.emplace(q, 0); while (queue.size()) { auto v = queue.top(); queue.pop(); if (fromq[v.i] < INF) continue; fromq[v.i] = v.d; for (auto &path : ps[v.i]) { if (fromq[path.first] < INF) continue; queue.emplace(path.first, v.d + path.second); } } queue.emplace(0, 0); while (queue.size()) { auto v = queue.top(); queue.pop(); if (from1[v.i] < INF) continue; from1[v.i] = v.d; for (auto &path : ps[v.i]) { if (from1[path.first] < INF) continue; queue.emplace(path.first, v.d + path.second); } } ll ans = -1; for (int i = 0; i < n; i++) { ll pcost = fromp[i] * 2; ll qcost = fromq[i] * 2; ll cost = from1[i] * 2; if (max(pcost, qcost) + cost <= t) { ans = max(ans, t - max(pcost, qcost)); } if (cost + pcost + qcost <= t) { ans = t; } } cout << ans << endl; return 0; }