#H2026C. Cautious Path
Cautious Path
Problem Description
You are given a directed graph with positive edge weights containing vertices and edges. Each edge can only be traversed from to , and it takes exactly units of time; except for its two endpoints, you may not enter, leave, or change direction inside the edge.
You start from vertex and aim to reach vertex . There are pursuers, and the -th pursuer initially stands at vertex . At time , you and all pursuers start moving simultaneously.
Before setting off, you must determine a directed walk from to as your escape route (revisiting vertices or edges is allowed). All pursuers know the entire route and each chooses any legal action to catch you as early as possible. You and the pursuers may only move along directed edges, and may wait at vertices arbitrarily. While you are inside an edge , you cannot stop or change direction, and you must move uniformly at speed . While a pursuer is inside an edge , the pursuer may stop, but cannot change direction; whenever the pursuer moves, the movement must be uniform at speed .
If at any time there exists at least one pursuer and you:
- are at the same vertex, or
- are at the same position inside the same directed edge,
then you are caught; arriving at the same position at the same time also counts as being caught. Even if you reach at the same moment a pursuer also reaches , that still counts as a failure.
Determine whether you can safely reach . If so, find the minimum time needed to safely reach .
Input Format
The first line contains three integers , representing the number of vertices, the number of edges, and the number of pursuers.
The next lines each contain three integers , describing a directed edge from to with traversal time .
The next line contains two integers , representing your starting vertex and ending vertex.
The last line contains integers , representing the initial vertices of the pursuers. When , this line is empty.
Output Format
If it is impossible to safely reach the destination, output:
NO
Otherwise output two lines:
YES
the minimum safe arrival time
Constraints
- Multiple edges and self-loops are allowed.
It is guaranteed that the answer, if it exists, does not exceed .
Sample
Input
6 8 1
1 2 2
2 6 10
1 3 1
3 4 1
4 6 5
5 2 1
5 3 7
5 6 8
1 6
5
Output
YES
7
Explanation
The pursuer reaches vertex at time at the earliest, so you cannot take . If you choose , the arrival times at the vertices are , all strictly earlier than the earliest times at which the pursuer can reach those vertices, so you can safely arrive.
相关
在下列比赛中: