#P15716. [JAG 2023 Summer Camp #2] Drifting
[JAG 2023 Summer Camp #2] Drifting
题目描述
You are given a weighted directed graph of vertices and edges, with vertices numbered to and edges numbered to . The -th () edge connects from vertex to vertex (), and the weight of the edge is .
Also, triplets of integers are given. The -th () triplet is ().
You start at vertex and move to vertex by repeatedly moving along an edge.
In addition, for all (), if you move from vertex to vertex directly, we must next move to a vertex other than vertex .
Judge whether it is possible to reach vertex . If it is possible to reach, also calculate the minimum sum of the weights of the edges you pass through.
输入格式
$$\begin{aligned} &N \ M \\ &u_1 \ v_1 \ w_1 \\ &u_2 \ v_2 \ w_2 \\ &\vdots \\ &u_M \ v_M \ w_M \\ &K \\ &a_1 \ b_1 \ c_1 \\ &a_2 \ b_2 \ c_2 \\ &\vdots \\ &a_K \ b_K \ c_K \end{aligned} $$The input satisfies the following constraints.
- All inputs consist of integers.
- $i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j) \ (1 \leq i, j \leq M)$
输出格式
If you cannot reach vertex , output . Otherwise, output the minimum sum of the weights of the edges you pass through.
4 4
1 2 1
1 3 2
2 4 2
3 4 2
1
1 2 4
4
7 8
1 2 5
1 3 2
2 4 1
3 4 1
4 5 6
4 6 2
5 7 1
6 7 1
2
2 4 5
3 4 6
9
3 2
1 2 1
2 3 1
1
1 2 3
-1
提示
In Sample Input 1, the best move is .
In Sample Input 2, the best move is $1 \rightarrow 2 \rightarrow 4 \rightarrow 6 \rightarrow 7$.