import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt() - 1; int q = sc.nextInt() - 1; long t = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int c = sc.nextInt(); graph.get(a).put(b, c); graph.get(b).put(a, c); } PriorityQueue queue = new PriorityQueue<>(); long[] fromS = new long[n]; queue.add(new Path(0, 0)); search(queue, fromS, graph); long[] fromP = new long[n]; queue.add(new Path(p, 0)); search(queue, fromP, graph); long[] fromQ = new long[n]; queue.add(new Path(q, 0)); search(queue, fromQ, graph); if (fromS[p] + fromS[q] + fromP[q] <= t) { System.out.println(t); return; } long max = -1; for (int i = 0; i < n; i++) { if ((fromS[i] + Math.max(fromP[i], fromQ[i])) * 2 <= t) { max = Math.max(max, t - Math.max(fromP[i], fromQ[i]) * 2); } } System.out.println(max); } static class Path implements Comparable { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } static void search(PriorityQueue queue, long[] costs, ArrayList> graph) { Arrays.fill(costs, Long.MAX_VALUE / 10); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (Map.Entry entry : graph.get(p.idx).entrySet()) { if (costs[entry.getKey()] == Long.MAX_VALUE / 10) { queue.add(new Path(entry.getKey(), p.value + entry.getValue())); } } } } }