from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def Dijkustra(lines,N,s):
    weight = [INF]*N
    weight[s] = 0

    def search (s,w_0,q,weight): #s->t
    	for line in list(lines[s]):
    		t = line[0]
    		w = w_0 + line[1]
    		if weight[t] > w:
    			heapq.heappush(q, [w,t])
    			weight[t] = w

    q = [[0,s]]
    heapq.heapify(q)
    while q:
    	w,n = heapq.heappop(q)
    	search(n,w,q,weight)

    return weight

N,M,P,Q,T = inpl()
S,P,Q = 0,P-1,Q-1
lines = defaultdict(set)
for _ in range(M):
    a,b,c = inpl()
    a,b = a-1,b-1
    lines[a].add((b,c))
    lines[b].add((a,c))

weight_S = Dijkustra(lines,N,S)
weight_P = Dijkustra(lines,N,P)
weight_Q = Dijkustra(lines,N,Q)

SP = weight_S[P]
SQ = weight_S[Q]
PQ = weight_P[Q]

if SP + PQ + SQ <= T:
    print(T)
elif SP*2 > T or SQ*2 > T:
    print(-1)
else:
    ans = 0
    for X1 in range(N):
        SX1 = weight_S[X1]
        PX1,QX1 = weight_P[X1], weight_Q[X1]
        for X2 in range(X1,N):
            SX2 = weight_S[X2]
            PX2,QX2 = weight_P[X2], weight_Q[X2]
            d = max(PX1+PX2,QX1+QX2)
            if d + SX1 + SX2 <= T:
                ans = max(ans,T-d)
    print(ans)