#include #include #include #include using namespace std; using i64 = int64_t; struct edge { int to; i64 cost; }; constexpr i64 inf = 987'654'321'987'654'321LL; template inline void readint(T *x) { *x = 0; int c; for(;;) { c = getchar_unlocked(); switch(c) case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: goto num; } num: for(;;) { switch(c) { case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: *x *= 10; *x += c - 48; break; default: return; } c = getchar_unlocked(); } } int N; vector> G; vector dijk(int s) { vector cost(N, inf); cost[s] = 0; priority_queue, vector>, greater>> pq; pq.emplace(0, s); vector seen(N, false); while(!pq.empty()) { i64 _; int v; tie(_, v) = pq.top(); pq.pop(); if(seen[v]) { continue; } seen[v] = true; for(edge &e : G[v]) { if(cost[e.to] > cost[v] + e.cost) { cost[e.to] = cost[v] + e.cost; pq.emplace(cost[e.to], e.to); } } } return cost; } int main(void) { int M, P, Q; i64 T; readint(&N); readint(&M); readint(&P); readint(&Q); readint(&T); G.assign(N, vector()); --P; --Q; for(int i=0; i c0 = dijk(0), c1 = dijk(P), c2 = dijk(Q); // 0 -> P -> Q -> 0 if(c0[P] + c1[Q] + c0[Q] <= T) { printf("%ld\n", T); return 0; } // 0 -> x -> P -> y -> 0 // Q i64 maxi = -1; for(int x=0; x