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 l = sc.nextInt() - 1; int[] trucks = new int[n]; ArrayList> graph = new ArrayList<>(); int count = 0; int[][] costs = new int[n][n]; for (int i = 0; i < n; i++) { trucks[i] = sc.nextInt(); if (trucks[i] > 0) { count++; } graph.add(new HashMap<>()); Arrays.fill(costs[i], Integer.MAX_VALUE); } if (count <= 1) { System.out.println(0); return; } 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<>(); for (int i = 0; i < n; i++) { queue.add(new Path(i, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[i][p.idx] <= p.value) { continue; } costs[i][p.idx] = p.value; for (Map.Entry entry : graph.get(p.idx).entrySet()) { if (costs[i][entry.getKey()] == Integer.MAX_VALUE) { queue.add(new Path(entry.getKey(), entry.getValue() + p.value)); } } } } long min = Long.MAX_VALUE; for (int i = 0; i < n; i++) { long max = Long.MIN_VALUE; long total = 0; for (int j = 0; j < n; j++) { if (trucks[j] > 0) { total += costs[i][j] * (long)trucks[j] * 2; max = Math.max(max, costs[i][j] - costs[j][l]); } } min = Math.min(min, total - max); } System.out.println(min); } static class Path implements Comparable { int idx; int value; public Path (int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }