#include #include #include #include using namespace std; const long long inf = 1LL << 62; struct edge { int to; long long cost; }; struct state { int pos; long long cost; }; bool operator<(const state& s1, const state& s2) { return s1.cost > s2.cost; } int main() { int N, M, P, Q; long long T; cin >> N >> M >> P >> Q >> T; --P, --Q; vector > G(N); for (int i = 0; i < M; ++i) { int a, b; long long c; cin >> a >> b >> c; --a, --b; G[a].push_back(edge{ b, c }); G[b].push_back(edge{ a, c }); } vector > dist(N, vector(N, inf)); for (int i = 0; i < N; ++i) { dist[i][i] = 0; priority_queue que; que.push(state{ i, 0 }); while (!que.empty()) { int u = que.top().pos; que.pop(); for (edge e : G[u]) { if (dist[i][e.to] > dist[i][u] + e.cost) { dist[i][e.to] = dist[i][u] + e.cost; que.push(state{ e.to, dist[i][e.to] }); } } } } if (dist[0][P] + dist[P][Q] + dist[Q][0] <= T) { cout << T << endl; } else { long long ans = -1; for (int i = 0; i < N; ++i) { long long div = max(dist[i][P], dist[i][Q]) * 2; if (div + dist[0][i] * 2 <= T) { ans = max(ans, T - div); } } cout << ans << endl; } return 0; }