import heapq def solve(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 M = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 C = list(map(int, data[idx:idx+M])) idx += M adj = [[] for _ in range(N+1)] for i in range(M): u = int(data[idx]) idx += 1 v = int(data[idx]) idx += 1 adj[u].append((v, i)) adj[v].append((u, i)) INF = 1 << 60 dist = [[INF] * (K+1) for _ in range(N+1)] dist[1][0] = 0 heap = [] heapq.heappush(heap, (0, 1, 0)) found = False answer = INF while heap: current_cost, u, used = heapq.heappop(heap) if u == N: answer = min(answer, current_cost) found = True continue if current_cost > dist[u][used]: continue for (v, idx_bridge) in adj[u]: cost = C[idx_bridge] # Option 1: do not use coupon if dist[v][used] > current_cost + cost: dist[v][used] = current_cost + cost heapq.heappush(heap, (dist[v][used], v, used)) # Option 2: use coupon if possible if used < K: if dist[v][used + 1] > current_cost: dist[v][used + 1] = current_cost heapq.heappush(heap, (dist[v][used + 1], v, used + 1)) if found: print(min(dist[N])) else: print(-1) solve()