{"raw_statement":[{"iden":"problem statement","content":"There are $N$ towns numbered $1, \\dots, N$, and $M$ roads numbered $1, \\dots, M$.  \nEvery road is directed; road $i$ $(1 \\leq i \\leq M)$ leads you from Town $A_i$ to Town $B_i$. The length of road $i$ is $C_i$.\nYou are given a sequence $E = (E_1, \\dots, E_K)$ of length $K$ consisting of integers between $1$ and $M$. A way of traveling from town $1$ to town $N$ using roads is called a **good path** if:\n\n*   the sequence of the roads' numbers arranged in the order used in the path is a subsequence of $E$.\n\nNote that a subsequence of a sequence is a sequence obtained by removing $0$ or more elements from the original sequence and concatenating the remaining elements without changing the order.\nFind the minimum sum of the lengths of the roads used in a good path.  \nIf there is no good path, report that fact."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq M, K \\leq 2 \\times 10^5$\n*   $1 \\leq A_i, B_i \\leq N, A_i \\neq B_i \\, (1 \\leq i \\leq M)$\n*   $1 \\leq C_i \\leq 10^9 \\, (1 \\leq i \\leq M)$\n*   $1 \\leq E_i \\leq M \\, (1 \\leq i \\leq K)$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $M$ $K$\n$A_1$ $B_1$ $C_1$\n$\\vdots$\n$A_M$ $B_M$ $C_M$\n$E_1$ $\\ldots$ $E_K$"},{"iden":"sample input 1","content":"3 4 4\n1 2 2\n2 3 2\n1 3 3\n1 3 5\n4 2 1 2"},{"iden":"sample output 1","content":"4\n\nThere are two possible good paths as follows:\n\n*   Using road $4$. In this case, the sum of the length of the used road is $5$.\n*   Using road $1$ and $2$ in this order. In this case, the sum of the lengths of the used roads is $2 + 2 = 4$.\n\nTherefore, the desired minimum value is $4$."},{"iden":"sample input 2","content":"3 2 3\n1 2 1\n2 3 1\n2 1 1"},{"iden":"sample output 2","content":"\\-1\n\nThere is no good path."},{"iden":"sample input 3","content":"4 4 5\n3 2 2\n1 3 5\n2 4 7\n3 4 10\n2 4 1 4 3"},{"iden":"sample output 3","content":"14"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}