#include using namespace std; typedef pair P; const int64_t INF = 1e18; vector dijkstra(int N, int s, vector

edges[]){ vector dist(N, INF); dist[s] = 0; priority_queue, greater

> que; que.push({0, s}); while(que.size()){ auto p = que.top(); que.pop(); int i = p.second; int64_t d = p.first; if(d > dist[i]) continue; for(auto& e : edges[i]){ int j = e.first; int64_t d2 = d + e.second; if(d2 < dist[j]){ dist[j] = d2; que.push({d2, j}); } } } return dist; } int main(){ int N, M, A, B, T; cin >> N >> M >> A >> B >> T; A--; B--; vector

edges[2000]; for(int i=0; i> a >> b >> c; edges[a-1].push_back({b-1, c}); edges[b-1].push_back({a-1, c}); } auto D0 = dijkstra(N, 0, edges); auto DA = dijkstra(N, A, edges); auto DB = dijkstra(N, B, edges); if(D0[A] + D0[B] + DA[B] <= T){ cout << T << endl; return 0; } int64_t ans = -1; for(int i=0; i= 0){ ans = max(ans, rest + 2*x); } } cout << ans << endl; return 0; }