import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int p = Integer.parseInt(sa[2]) - 1; int q = Integer.parseInt(sa[3]) - 1; int t = Integer.parseInt(sa[4]); Map> map = new HashMap>(); for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; int c = Integer.parseInt(sa[2]); List list1 = map.get(a); if (list1 == null) { list1 = new ArrayList(); map.put(a, list1); } Road r = new Road(); r.v = b; r.c = c; list1.add(r); List list2 = map.get(b); if (list2 == null) { list2 = new ArrayList(); map.put(b, list2); } r = new Road(); r.v = a; r.c = c; list2.add(r); } br.close(); int[] x = {0, p, q}; long[][] d = new long[3][n]; for (int i = 0; i < x.length; i++) { Arrays.fill(d[i], Long.MAX_VALUE); d[i][x[i]] = 0; PriorityQueue que = new PriorityQueue(); City f = new City(); f.v = x[i]; f.d = 0; que.add(f); while (!que.isEmpty()) { City cur = que.poll(); List list = map.get(cur.v); for (Road next : list) { long alt = d[i][cur.v] + next.c; if (d[i][next.v] > alt) { d[i][next.v] = alt; City c = new City(); c.v = next.v; c.d = alt; que.add(c); } } } } if (d[1][0] * 2 > t || d[2][0] * 2 > t) { System.out.println(-1); return; } if (d[0][p] + d[1][q] + d[0][q] <= t) { System.out.println(t); return; } long min = Long.MAX_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long val = Math.max(d[1][i] + d[1][j], d[2][i] + d[2][j]); if (d[0][i] + val + d[0][j] <= t) { min = Math.min(min, val); } } } System.out.println(t - min); } static class Road implements Comparable { int v, c; public int compareTo(Road o) { return c - o.c; } } static class City implements Comparable { int v; long d; public int compareTo(City o) { if (d > o.d) { return 1; } else if (d == o.d) { return 0; } else { return -1; } } } }