import heapq import sys n, m, p, q, t=map(int, input().split()) p-=1 q-=1 g=[[] for i in range(n)] for i in range(m): a, b, c=map(int, input().split()) a-=1 b-=1 g[a].append((c, b)) g[b].append((c, a)) def dijkstra(s): d=[10**18]*n d[s]=0 que=[] heapq.heappush(que, (0, s)) while len(que)!=0: u=heapq.heappop(que) x=u[1] if d[x]d[x]+v[0]: d[y]=d[x]+v[0] heapq.heappush(que, (d[y], y)) return d d1=dijkstra(0) dp=dijkstra(p) dq=dijkstra(q) if d1[p]+dp[q]+d1[q]<=t: print(t) sys.exit() elif max(d1[p]*2, d1[q]*2)>t: print(-1) sys.exit() ans=0 for i in range(n): for j in range(n): if d1[i]+max(dp[i]+dp[j], dq[i]+dq[j])+d1[j]<=t: ans=max(ans, t-max(dp[i]+dp[j], dq[i]+dq[j])) print(ans)