#include #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair P; const int mod = 1000000007; const int INF = 1e18; const int MAX_V = 2010; struct edge{ int to, cost; edge(int to, int cost):to(to), cost(cost){} }; vector G[MAX_V]; struct Dijkstra{ vector d; Dijkstra(){} Dijkstra(int V){ d.resize(V, INF); } void calc(int s){ d[s] = 0; priority_queue, greater

> q; q.push(P(d[s], s)); while(!q.empty()){ P p = q.top(); q.pop(); int from = p.second; int cost = p.first; if(d[from] < cost) continue; rep(i, 0, G[from].size()){ int next = G[from][i].to; int newCost = cost + G[from][i].cost; if(d[next] > newCost){ d[next] = newCost; q.push(P(newCost, next)); } } } } }; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, p, q, t; cin >> n >> m >> p >> q >> t; p--; q--; rep(i, 0, m){ int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } Dijkstra dp(n), dq(n), ds(n); dp.calc(p); dq.calc(q); ds.calc(0); int ans = -1; if(ds.d[p] + dp.d[q] + ds.d[q] <= t){ ans = t; } rep(i, 0, n){ rep(j, 0, n){ int tp = ds.d[i] + dp.d[i] + dp.d[j] + ds.d[j]; int tq = ds.d[i] + dq.d[i] + dq.d[j] + ds.d[j]; if(tp <= t && tq <= t){ int tmp = ds.d[i] + ds.d[j] + (t - max(tp, tq)); ans = max(ans, tmp); } } } cout << ans << endl; }