from heapq import heappush,heappop n,m,p,q,t = map(int,input().split()) e = [[] for i in range(n)] for _ in range(m): a,b,c = map(int,input().split()) a,b = a-1,b-1 e[a].append([b,c]) e[b].append([a,c]) p,q = p-1,q-1 inf = 10**20 mod = 1<<16 def dijkstra(x): dis = [inf]*n dis[x] = 0 h = [x] while h: d,now = divmod(heappop(h),mod) if dis[now] != d: continue for nex,c in e[now]: if dis[nex] > d+c: dis[nex] = d+c heappush(h,((d+c)<<16)+nex) return dis dis0 = dijkstra(0) disp = dijkstra(p) disq = dijkstra(q) ans = -1 if dis0[p]+dis0[q]+disp[q] <= t: print(t) exit() for i in range(n): for j in range(n): t1 = dis0[i] t2 = dis0[j] t3 = max(disp[i]+disp[j],disq[i]+disq[j]) if t1+t2+t3 > t: continue ans = max(ans,t-t3) if ans == inf: ans = -1 print(ans)