P2559 [AHOI2002] Harry Potter and the Sorcerer's Stone

Description

![](https://cdn.luogu.com.cn/upload/pic/1681.png)

Input Format

The first line of the input file contains seven numbers, namely $S_1, S_2, \dots, S_7$. The second line contains two numbers: the starting city $i$ and the destination city $j$. The third line contains a positive integer $c$, with $c \le 10000$, indicating that each of the following $c$ lines stores a pair of cities that are directly reachable from each other. The information for a pair of directly reachable cities consists of three numbers: the indices of the two cities and the terrain type between these two cities. City indices are positive integers not exceeding $100$, but the indices are not necessarily continuous. On the same line in the file, any two adjacent numbers are separated by a single whitespace character.

Output Format

Output a single line with the time required by the fastest route between the starting city $i$ and the destination city $j$.

Explanation/Hint

Translated by ChatGPT 5