from heapq import heapify as hpi , heappop as hpop , heappush as hpush n,m,p,q,t=map(int,input().split()) g = [[] for i in range(n+1)] for _ in range(m): x,y,z = map(int,input().split()) g[x].append((y,z)) g[y].append((x,z)) def daiku(i): inf=float('inf') d = [inf for i in range(n+1)] d[i] = 0 done=[0 for i in range(n+1)] hp=[] hpush(hp,(d[i],i)) while hp: _ ,now= hpop(hp) if done[now]: continue done[now] = 1 for go,cost in g[now]: if d[go] > d[now] + cost: d[go] = d[now] + cost hpush(hp,(d[go],go)) return d one=daiku(1) ps=daiku(p) qs=daiku(q) ans = -1 if one[p]+ps[q]+qs[1] <= t: ans = t for i in range(1,n+1): for j in range(1,n+1): tt=one[i] + max(ps[i]+ ps[j],qs[j] + qs[i]) +one[j] sepa=max(ps[i] + ps[j] , qs[i] + qs[j]) if tt > t: continue ans=max(t-sepa,ans) print(ans)