#include using namespace std; using P = pair; using Graph = vector>; void dijkstra(const Graph &G, vector &dist, int s) { priority_queue, greater

> que; dist[s] = 0; que.emplace(dist[s], s); while (!que.empty()){ auto p = que.top(); que.pop(); int v = p.second; if (dist[v] < p.first) continue; for (auto np : G[v]) { auto nv = np.second; auto dis = np.first; if (dist[nv] > dist[v] + dis) { dist[nv] = dist[v] + dis; que.emplace(dist[nv], nv); } } } } int main() { int N, M, P, Q; long long T; cin >> N >> M >> P >> Q >> T; P--; Q--; Graph G(N); for (int i = 0; i < M; i++) { int a, b; long long c; cin >> a >> b >> c; a--; b--; G[a].emplace_back(c, b); G[b].emplace_back(c, a); } vector dist(N, 1LL << 60), distP(N, 1LL << 60), distQ(N, 1LL << 60); dijkstra(G, dist, 0); dijkstra(G, distP, P); dijkstra(G, distQ, Q); if (dist[P] + dist[Q] + distP[Q] <= T) { cout << T << endl; return 0; } long long ans = -1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (max(dist[i] + distP[i] + distP[j] + dist[j], dist[i] + distQ[i] + distQ[j] + dist[j]) > T) continue; ans = max(ans, T - max(distP[i] + distP[j], distQ[i] + distQ[j])); } } cout << ans << endl; }