#include using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(LL i = (l) ; i < (r); ++i) #define incII(i, l, r) for(LL i = (l) ; i <= (r); ++i) #define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i) #define decII(i, l, r) for(LL i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template bool setmin (T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template bool setmax (T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC(v.size()) #define SL(v) SC(v.size()) #define RF(e, v) for(auto & e: v) #define ef else if #define UR assert(false) // ---- ---- template class RPQ : public priority_queue, greater> { }; template void dijkstra(int s, vector> g[], C d[]) { RPQ> q; d[s] = 0; q.emplace(d[s], s); while(! q.empty()) { C c = q.top().FI; int v = q.top().SE; q.pop(); if(d[v] != c) { continue; } for(auto & e : g[v]) { int ev = e.FI; C ec = e.SE; if(setmin(d[ev], d[v] + ec)) { q.emplace(d[ev], ev); } } } } LL n, m, p, q, t, d[3][2000], INF = 1e15; vector> g[2000]; int main() { cin >> n >> m >> p >> q >> t; p--; q--; inc(i, m) { LL a, b, c; cin >> a >> b >> c; a--; b--; g[a].EB(b, c); g[b].EB(a, c); } inc(k, 3) { inc(i, n) { d[k][i] = INF; } } dijkstra(0, g, d[0]); dijkstra(p, g, d[1]); dijkstra(q, g, d[2]); if(d[0][p] + d[1][q] + d[2][0] <= t) { cout << t << endl; } ef(max(d[0][p], d[0][q]) * 2 > t) { cout << -1 << endl; } else { LL ans = 0; inc(i, n) { if(2 * (d[0][i] + d[1][i]) > t) { continue; } if(2 * (d[0][i] + d[2][i]) > t) { continue; } setmax(ans, t - max(d[1][i], d[2][i]) * 2); } cout << ans << endl; } return 0; }