import java.util.*; public class Main { static final long MAX = Long.MAX_VALUE / 10; 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; int 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<>(); queue.add(new Path(p, 0)); long[] pCosts = getCost(n, queue, graph); queue.add(new Path(q, 0)); long[] qCosts = getCost(n, queue, graph); queue.add(new Path(0, 0)); long[] zCosts = getCost(n, queue, graph); if (Math.max(pCosts[0], qCosts[0]) * 2 > t) { System.out.println(-1); return; } if (pCosts[0] + pCosts[q] + qCosts[0] <= t) { System.out.println(t); return; } long max = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (Math.max(pCosts[i] + pCosts[j], qCosts[i] + qCosts[j]) + zCosts[i] + zCosts[j] <= t) { max = Math.max(max, t - Math.max(pCosts[i] + pCosts[j], qCosts[i] + qCosts[j])); } } } System.out.println(max); } static long[] getCost(int size, PriorityQueue queue, ArrayList> graph) { long[] costs = new long[size]; Arrays.fill(costs, MAX); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx).keySet()) { queue.add(new Path(x, p.value + graph.get(p.idx).get(x))); } } return costs; } 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; } } } }