from heapq import * n,m,p,q,t=map(int,input().split()) to={} for _ in range(m): a,b,c=map(int,input().split()) to.setdefault(a,[]) to.setdefault(b, []) to[a].append([b,c]) to[b].append([a,c]) sy=[[-1]*(n+1) for _ in range(n+1)] for s in range(1,n+1): hp = [] heappush(hp, [0, s]) syr=sy[s] while hp: ji, g = heappop(hp) if syr[g] != -1: continue syr[g] = ji for ng, dt in to[g]: if syr[ng] != -1: continue heappush(hp, [ji + dt, ng]) if sy[1][p]+sy[1][q]+sy[p][q]<=t: print(t) elif sy[1][p]*2>t or sy[1][q]*2>t: print(-1) else: mn=t for w in range(1,n+1): if w in [p,q]:continue for a in range(1,n+1): mx=max(sy[w][p]+sy[p][a],sy[w][q]+sy[q][a]) if sy[1][w]+mx+sy[a][1]<=t: mn=min(mn,mx) print(t-mn)