from heapq import heappush, heappop INF = 10 ** 9 def dijkstra(s, n): # (始点, ノード数) dist = [INF] * n hq = [(0, s)] # (distance, node) dist[s] = 0 seen = [False] * n # ノードが確定済みかどうか while hq: v = heappop(hq)[1] # ノードを pop する seen[v] = True for to, cost in adj[v]: # ノード v に隣接しているノードに対して if seen[to] == False and dist[v] + cost < dist[to]: dist[to] = dist[v] + cost heappush(hq, (dist[to], to)) return dist n,m,p,q,t = map(int,input().split()) p -= 1 q -= 1 adj = [[] for i in range(n)] for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 adj[a].append([b,c]) adj[b].append([a,c]) fst = dijkstra(0,n) ans = t-2*max(fst[p],fst[q]) for i in range(1,n): rt = dijkstra(i,n) tmp = 2*fst[i] tmp += 2*max(rt[p],rt[q]) if tmp <= t: ans = max(ans,t-tmp+2*fst[i]) print(max(ans,-1))