## https://yukicoder.me/problems/no/1812 import heapq MAX_INT = 10 ** 18 def dijkstra(N, edges, start): next_nodes = [[] for _ in range(N)] for u, v, c in edges: next_nodes[u].append((v , c)) next_nodes[v].append((u , c)) fix = [MAX_INT] * N seen = [MAX_INT] * N seen[start] = 0 queue = [] heapq.heappush(queue, (0, start)) while len(queue) > 0: cost, v = heapq.heappop(queue) if fix[v] < MAX_INT: continue fix[v] = cost for w, c in next_nodes[v]: if fix[w] < MAX_INT: continue new_cost = c + cost if seen[w] > new_cost: seen[w] = new_cost heapq.heappush(queue, (new_cost, w)) return fix def main(): N, M, K = map(int, input().split()) R = list(map(int, input().split())) edges = [] for _ in range(M): A, B, C = map(int, input().split()) edges.append((A - 1, B - 1, C)) dists_map = {} dists_map[0] = dijkstra(N, edges, 0) for r in R: u, v, _ = edges[r - 1] dists_map[u] = dijkstra(N, edges, u) dists_map[v] = dijkstra(N, edges, v) dp = [{} for _ in range(2 ** K)] dp[0][0] = 0 for bit in range(2 ** K): for start_key, cost in dp[bit].items(): for r_index in range(K): if bit & (1 << r_index) > 0: continue new_bit = bit | (1 << r_index) u, v, c = edges[R[r_index] - 1] new_start_key = v new_cost = dists_map[start_key][u] + cost + c if new_start_key not in dp[new_bit]: dp[new_bit][new_start_key] = MAX_INT dp[new_bit][new_start_key] = min(dp[new_bit][new_start_key], new_cost) new_start_key = u new_cost = dists_map[start_key][v] + cost + c if new_start_key not in dp[new_bit]: dp[new_bit][new_start_key] = MAX_INT dp[new_bit][new_start_key] = min(dp[new_bit][new_start_key], new_cost) answer = MAX_INT for start_key, cost in dp[-1].items(): d = dists_map[start_key][N - 1] answer = min(answer, d + cost) if answer == MAX_INT: print(-1) else: print(answer) if __name__ == "__main__": main()