A Monster for Gallina’s owner

Marc is leaving his flat to go to the university. He has been working hard for the last couple of days to fool everyone into believing that he has made some progress on his PhD thesis. Furthermore, he had to find food for Gallina, his Minecraft parrot. Since he feels really tired, he urgently needs to buy a Monster energy drink (and also because he is severely addicted).

Marc decides to buy it on his way to the university. How many seconds will it take him to get there, if he does so optimally? We model the city as a weighted undirected graph with nn vertices (from 0 to n1n-1) and mm edges. Marc’s flat is at vertex 0, and the university is at vertex n1n - 1. There are kk supermarkets. Marc will spend exactly one minute inside a supermarket to buy his drink.

Input

Input consists of several cases, each with nn, mm and kk, followed by mm triples xx yy cc for an edge between xx and yy (with xyx \ne y) that takes cc seconds to transverse (an integer). Follow the kk positions of the supermarkets, all different and between 1 and n2n - 2. Assume 3n1043 \le n \le 10^4, 2m5n2 \le m \le 5n, 1kn21 \le k \le n - 2, that there is at most one edge between every pair of vertices, and 1c1051 \le c \le 10^5.

Output

For each case, print the minimum time to reach the university buying a Monster drink, if it is possible. Otherwise, print “impossible”.

Problem information

Author: Víctor Martín and Marc Felipe

Generation: 2026-01-25T11:24:52.871Z

© Jutge.org, 2006–2026.
https://jutge.org