#include #include #include #include using namespace std; typedef long long ll; typedef pair Pa; struct edge{ ll to,dist; }; ll N,M,P,Q,T; ll inf = 1e18; vector> v(2010); void Dijkstra(int s,vector& dp){ priority_queue Q; dp[s] = 0; Q.push({0,s}); while(!Q.empty()){ Pa p = Q.top(); Q.pop(); if(dp[p.second]p.first+x.dist){ dp[x.to] = p.first+x.dist; Q.push({dp[x.to],x.to}); } } } } int main(){ cin >> N >> M >> P >> Q >> T; ll a,b,c; for(int i=0;i dp1(N+1,inf),dp2(N+1,inf),dp3(N+1,inf); Dijkstra(1,dp1); Dijkstra(P,dp2); Dijkstra(Q,dp3); ll ans = -1; for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){ ll t = dp1[i]+dp1[j]+max(dp2[i]+dp2[j],dp3[i]+dp3[j]); if(t<=T) ans = max(ans,T-max(dp2[i]+dp2[j],dp3[i]+dp3[j])); } if(2*(min(dp1[P],dp1[Q])+dp2[Q])<=T) ans = T; if(dp1[P]+dp1[Q]+dp2[Q]<=T) ans = T; cout << ans << endl; }