//#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; //typedef unsigned __int128 HASH; typedef pair pii; typedef pair pll; typedef pair pullull; typedef pair plli; typedef pair pdi; typedef pair pdbi; typedef pair pipii; typedef pair plpll; typedef vector vi; typedef vector vll; typedef vector vvi; typedef vector vvvi; typedef vector vpii; typedef vector> mat; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n);i>0;i--) #define rrep2(i,a,b) for (int i=(a);i>b;i--) #define pb push_back #define fi first #define se second #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() const ll hmod1 = 999999937; const ll hmod2 = 1000000000 + 9; const int INF = 1<<30; const ll INFLL = 1LL<<62; const long double EPS = 1e-12; const ll mod = 1000000000 + 7; //const ll mod = 998244353; const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1}; const long double pi = 3.141592653589793; #define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod #define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false //debug #define DEBUG #define DUMPOUT cerr #ifdef DEBUG #define dump(...) DUMPOUT<<#__VA_ARGS__<<" :["<<__FUNCTION__<<":"<<__LINE__<<"]"< void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) DUMPOUT << " "; else DUMPOUT << ", "; dump_func(std::move(tail)...); } //ostream template ostream& operator << (ostream& os, vector& vec) { os << "["; for (int i = 0; i ostream& operator << (ostream& os, pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template ostream& operator << (ostream& os, map& map_var) { os << "["; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "]"; return os; } template ostream& operator << (ostream& os, set& set_var) { os << "["; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "]"; return os; } int n, m, p, q, t; struct edge{int to, cost;}; vector> g(2000 + 5); vector dijkstra(int s, int n, vector>& g){ priority_queue, greater> pque; vector d(n, INFLL); d[s] = 0; pque.push(plli(0, s)); while (!pque.empty()){ plli p = pque.top(); pque.pop(); int fr = p.second; if (d[fr] < p.first) continue; for (edge e: g[fr]){ if (d[e.to] > d[fr] + e.cost){ d[e.to] = d[fr] + e.cost; pque.push(plli(d[e.to], e.to)); } } } return d; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> p >> q >> t; p--; q--; rep(i, m) { int u, v, c; cin >> u >> v >> c; u--; v--; g[u].push_back(edge{v, c}); g[v].push_back(edge{u, c}); } vector d1 = dijkstra(0, n, g); if (2 * d1[p] > t || 2 * d1[q] > t) { cout << -1 << endl; return 0; } vector dp = dijkstra(p, n, g); vector dq = dijkstra(q, n, g); if (d1[p] + dp[q] + dq[0] <= t) { cout << t << endl; return 0; } vector> GO(n); vector> BACK(n); rep(i, n) { GO[i] = {d1[i], {d1[i] + dp[i], d1[i] + dq[i]}}; BACK[i] ={d1[i], {dp[i], dq[i]}}; } int ans = -1; rep(i, n) { if (i == p || i == q) continue; int yuki1 = GO[i].se.fi; int yuki2 = GO[i].se.se; int Same = GO[i].fi; rep(j, n) { if (j == p || j == q) continue; int tmp_yuki1 = yuki1 + BACK[j].se.fi; int tmp_yuki2 = yuki2 + BACK[j].se.se; int tmpT = d1[j] + max(tmp_yuki1, tmp_yuki2); Same += d1[j]; if (tmpT <= t) { ans = max(ans, Same + t - tmpT); } } } cout << ans << endl; }