No.2805 Go to School
タグ : / 解いたユーザー数 86
作問者 :
highlighter
Magentor
keisuke6
fact493
Problem Statement
Kuroinu is about to go from his home to school.
There are $N$ locations, numbered $1,2\dots N$.
There are also $M$ roads connecting locations. Road $i(1\leq i\leq M)$ allows travel between location $a_i$ and location $b_i$ in both directions, taking $t_i$ minutes each way. Note that there may be roads connecting a location to itself, and there may be multiple roads between the same pair of locations.
Kuroinu's home is at location $1$, and the school is at location $N$.
Initially, Kuroinu is at location $1$.
Kuroinu can move between locations along roads, and can stay at his current location for any amount of time.
Starting $S$ minutes from the beginning, Kuroinu has a stomachache for $E+0.01$ minutes, so during that period he needs to go to a toilet to relieve himself.
There are $L$ toilets, located at locations $T_j(1\leq j\leq L)$. Here, $T_L=N$. Using a toilet takes $1$ minute.
In other words, he must arrive at a location with a toilet between $S$ minutes and $S+E-0.99$ minutes from the beginning, and stay there for at least $1$ minute.
Find the minimum number of minutes required to reach the school after having relieved himself. Under the constraints of this problem, it can be proved that this value, if it exists, is an integer.
However, if he cannot make it to a toilet in time or cannot reach the school, output -1.
Input
$N~~~M~~~L~~~S~~~E$ $a_1~~~b_1~~~t_1$ $a_2~~~b_2~~~t_2$ $\vdots$ $a_M~~~b_M~~~t_M$ $T_1~~~T_2~~~\dots~~~T_L$
Constraints
- $2\leq N\leq 2\times10^5$
- $1\leq M\leq 2\times10^5$
- $1\leq L\leq N$
- $1\leq S,E \leq 10^9$
- $1\leq a_i,b_i\leq N$
- $1\leq t_i\leq 10^9(1\leq i\leq M)$
- $1\leq T_1 \lt T_2 \lt \dots \lt T_L= N$
- All inputs are integers
Output
Output the answer on $1$ line.
Also, print a newline at the end.
Sample
Sample 1
Input
5 6 3 4 2 1 2 3 1 3 2 2 4 5 2 3 2 4 5 6 1 4 2 2 3 5
Output
15
It is optimal to go from location $1$ to location $3$, wait until $S$ minutes, use the toilet, and then go to location $5$.
Sample 2
Input
4 4 4 5 3 1 2 2 1 3 3 1 4 4 2 3 1 1 2 3 4
Output
6
It is possible to arrive at school before the stomachache begins, but since he must use a toilet first, he uses the toilet at location $4$, which is the school.
Sample 3
Input
6 6 2 4 5 1 3 4 2 3 2 6 4 2 3 4 3 1 2 1 1 5 3 5 6
Output
9
He goes to location $6$ and uses the toilet at location $6$.
Sample 4
Input
4 3 1 3 4 1 3 2 2 3 2 1 3 1 4
Output
-1
He cannot reach the school in the first place.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。