#include #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll LINF = (1LL << 60) - 1LL; constexpr double eps = 1e-9; constexpr ll MOD = 1000000007LL; template bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }; template bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }; template ostream& operator<<(ostream& os, vector v) { for(int i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "\n" : " "); } return os; } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value == 0>::type fill_v(T& t, const V& v) { t = v; } template typename enable_if::value != 0>::type fill_v(T& t, const V& v) { for(auto& e : t) { fill_v(e, v); } }; ll n, m, p, q, t; struct edge { ll to, cost; }; vector> G; vector dijkstra(int s) { vector d(n, LINF); priority_queue, greater

> q; d[s] = 0; q.push(P(0, s)); while(!q.empty()) { int v = q.top().second; q.pop(); for(auto e : G[v]) { if(d[e.to] <= d[v] + e.cost) continue; d[e.to] = d[v] + e.cost; q.push(P(d[e.to], e.to)); } } return d; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> p >> q >> t; --p; --q; G.resize(n); for(int i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back({b, c}); G[b].push_back({a, c}); } auto d = dijkstra(0); auto dp = dijkstra(p); auto dq = dijkstra(q); if(d[q] + dq[p] + dp[0] <= t) { cout << t << endl; return 0; } ll ans = -1; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { ll t1 = d[i] + max(dq[i] + dq[j], dp[i] + dp[j]); if(t1 + d[j] > t) { continue; } chmax(ans, d[i] + t - t1); } } cout << ans << endl; }