|
Natsu |
Today is the final day, standard-bearers of our band. ...It has been a long expedition. |
|
Kazusa |
Yoshimi |
Airi |
…… |
|
Natsu |
We have taken the long way round, but at last we stand before the decisive battle. We may have wandered at times, but not all who wander are lost. Every step has given us the nourishment we needed. |
|
Natsu |
The first line contains , , , separated by spaces. ; ;
If it is possible to start at vertex , visit at least one dessert cafe vertex, and reach vertex , print the minimum travel cost on the first line.
If no such journey can visit a dessert cafe vertex, print -1 on the first line.
I know it will be difficult. The test is demanding, and we are still a ragtag band. But that changes nothing. The semla awaits, and the test must be taken...
|
Natsu |
...Well then, what is there to hesitate over? |
|
Natsu |
Do not falter! If we each do our part and look out for one another, this long expedition will end with the full stop exactly where we want it! We did not practice all this time merely to make memories! |
|
Natsu |
Claim the semla that shall fill your stomachs!! The After-School Sweets Brigade shall prevail! |
Hello, Sensei. It's Airi. The After-School Sweets Club has finished our final band practice at school, and we're about to head to the concert venue. But getting there has become a little complicated...
We need to take buses from school to the venue. There are regular buses and loop buses, and their fares work differently. And since we're the After-School Sweets Club, stopping at a dessert cafe before the show is a must, right? But we don't have much money, so we need to find the cheapest way to get to the venue.
Natsu is the best at explaining things, so I asked her to explain the rest.
In a directed graph with vertices and weighted edges, the After-School Sweets Club must travel from the school at vertex to the concert venue at vertex . They must visit at least one dessert cafe before reaching the venue, while minimizing the total cost of the journey. There is always a way to reach the venue from the school.
Among the vertices other than the school at vertex and the venue at vertex , are dessert cafes. The club may take regular buses and loop buses any number of times. However, once they visit the venue by bus, they do not travel anywhere else. The two types of buses work as follows.
Regular bus
Loop bus
...That's what Natsu told me to write.
Sensei, please find the minimum cost for us to reach the concert venue.
The second line contains the vertex numbers of the dessert cafes, separated by spaces. These vertex numbers are between and , inclusive.
The next lines, starting from the third line, describe the edges. The -th of these lines contains , , , separated by spaces, representing a directed edge from vertex to vertex with weight . ; ; For any two distinct edges , .