#include #define Int int64_t using namespace std; using P = pair; struct edge { int to; Int cost; }; void dijkstra(vector>& G, vector& d, int s) { priority_queue, greater

> que; d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) { continue; } for (int i = 0; i < G[v].size(); ++i) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { const Int INF = 1e18; Int N, M, P, Q, T; cin >> N >> M >> P >> Q >> T; --P; --Q; vector> G(N); for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back({b, c}); G[b].push_back({a, c}); } vector d0(N, INF), dP(N, INF), dQ(N, INF); dijkstra(G, d0, 0); dijkstra(G, dP, P); dijkstra(G, dQ, Q); if (d0[P] + dP[Q] + dQ[0] <= T) { cout << T << endl; return 0; } Int res = -1; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { Int x = d0[i] + d0[j]; Int y = max(dP[i] + dP[j], dQ[i] + dQ[j]); if (x + y <= T) { res = max(res, T - y); } } } cout << res << endl; return 0; }