#P14726. [ICPC 2022 Seoul R] Forbidden Turns
[ICPC 2022 Seoul R] Forbidden Turns
题目描述
A GPS navigation company ICPC (International Control Perfection Company) designs a car navigation system for a transportation network. The system abstracts the transportation network as a directed graph with edge cost . For a directed edge , denotes the distance from a place to another place . The company wants to implement the shortest path module in the system. To reflect the normal situation that we cannot turn to some directions in a junction of transportation network, we want to find the shortest path that does not contain forbidden turns as a subpath.
A path from to is a sequence of vertices where , , for . Unlike the common definition of the path, you are here allowed to repeat the same vertices in a path one or more. A subpath of a path is a contiguous subsequence of the sequence that corresponds to the path. A forbidden turn is a path (i.e., triplet) such that and and . The distance of a path is defined as . The shortest path from to is a path from to with the minimum distance. The company wants to find the distance of the shortest path that avoids the forbidden turns between two designated vertices. Note that the shortest path from to has distance 0 and it avoids all the forbidden turns.
Let's see the following example in the figure below. Each edge cost lies beside each edge and the list of three forbidden turns are in the right box. The shortest path without forbidden turns from the vertex 3 to the vertex 2 is which is denoted as blue arrows in the following figure. The distance of the shortest path is . Note that we cannot take the shorter paths and since they contain forbidden turns and , respectively.
:::align{center}
:::
Given a directed graph with the edge cost , a set of forbidden turns , and two vertices and , write a program to output the distance of the shortest path from to that avoids all the forbidden turns. We assume that out-degree of each vertex , i.e., the number of edges that starts from is at most 10.
输入格式
Your program is to read from standard input. The input starts with a line containing three integers, , , and . (, , ), where is the number of directed edges, is the number of vertices, and is the number of forbidden turns of the given directed graph . Here, is less than or equal to the number of all the possible forbidden turns in the given directed graph . The vertices are numbered from 0 to . The second line contains two integers and which denote the source and destination vertices, respectively. In the following lines, the -th line contains three integers , , and ( and ) which denotes an edge and its cost, respectively. In the following lines, the -th line contains three integers , , and which denote a forbidden turn .
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain an integer that represents the distance of the shortest path from to which avoids all the forbidden turns. If such a path does not exist, the line should contain .
9 7 3
3 2
6 3 2
3 0 3
0 1 12
1 0 4
1 2 2
1 5 4
4 1 8
5 4 7
5 2 5
0 1 2
4 1 5
1 5 2
36
4 4 1
0 3
0 1 2
1 2 3
0 2 7
2 3 10
0 1 2
17
4 4 0
0 3
0 1 2
1 2 3
0 2 7
2 3 10
15