import heapq def aa(m): global n hq=[];heapq.heappush(hq,(0,m)) res=[1<<60]*n;res[m]=0 while hq: q,w=heapq.heappop(hq) if res[w]q+j: res[i]=q+j heapq.heappush(hq,(res[i],i)) return res n,m,p,q,t=map(int,input().split());q-=1;p-=1 v=[[] for i in range(n)] for i in range(m): a,b,c=map(int,input().split());a-=1;b-=1 v[a].append((b,c));v[b].append((a,c)) x,y,z=aa(0),aa(p),aa(q) if max(x[q]*2,x[p]*2)>t: print(-1);exit() if x[q]+x[p]+y[q]<=t: print(t);exit() ans=0 for i in range(n): for j in range(n): if max(y[i]+y[j],z[i]+z[j])+x[i]+x[j]<=t: ans=max(ans,t-max(y[i]+y[j],z[i]+z[j])) print(ans)