[ABC277E] 水晶开关图 (Crystal Switches)
Score : points
Problem Statement
You are given an undirected graph consisting of vertices and edges.
For , the -th edge is an undirected edge connecting vertex and that is initially passable if and initially impassable if . Additionally, there are switches on of the vertices: vertex , vertex , , vertex .
Takahashi is initially on vertex , and will repeat performing one of the two actions below, Move or Hit Switch , which he may choose each time, as many times as he wants.
-
Move: Choose a vertex adjacent to the vertex he is currently on via an edge, and move to that vertex.
-
Hit Switch: If there is a switch on the vertex he is currently on, hit it. This will invert the passability of every edge in the graph. That is, a passable edge will become impassable, and vice versa.
Determine whether Takahashi can reach vertex , and if he can, print the minimum possible number of times he performs Move before reaching vertex .
Constraints
-
-
-
-
-
-
-
-
All values in the input are integers.
Input
The input is given from Standard Input in the following format:
$N$ $M$ $K$
$u_1$ $v_1$ $a_1$
$u_2$ $v_2$ $a_2$
$\vdots$
$u_M$ $v_M$ $a_M$
$s_1$ $s_2$ $\ldots$ $s_K$
Output
If Takahashi cannot reach vertex , print ; if he can, print the minimum possible number of times he performs Move before reaching vertex .
Sample Input 1
5 5 2
1 3 0
2 3 1
5 4 1
2 1 1
1 4 0
3 4
Sample Output 1
5
Takahashi can reach vertex as follows.
-
Move from vertex to vertex .
-
Move from vertex to vertex .
-
Hit the switch on vertex . This inverts the passability of every edge in the graph.
-
Move from vertex to vertex .
-
Move from vertex to vertex .
-
Hit the switch on vertex . This again inverts the passability of every edge in the graph.
-
Move from vertex to vertex .
Here, Move is performed five times, which is the minimum possible number.
Sample Input 2
4 4 2
4 3 0
1 2 1
1 2 0
2 1 1
2 4
Sample Output 2
-1
The given graph may be disconnected or contain multi-edges. In this sample input, there is no way for Takahashi to reach vertex , so you should print .