#P8914. [DMOI-R2] 梦境
[DMOI-R2] 梦境
Background
Little A had a nightmare.
Problem Description
Little A’s dreamland can be seen as an undirected graph with nodes and edges. Little A is at node , a monster is at node , and the safe house is at node .
The monster is chasing Little A, and Little A needs to escape to the safe house. Little A realizes this is his own dream, so he can control it to some extent. He sets the monster’s moving speed to , but the cost is that his own moving speed is set to .
Little A will always walk along a shortest path to . If there are multiple shortest paths, Little A will choose the one whose sequence of visited node indices in order is lexicographically smallest, because he thinks this makes it least likely to be caught.
The monster wanders in the dreamland. It moves randomly to a neighboring node, and it will not visit any node that it has already visited again.
Now Little A needs to know in the worst case whether he can safely reach the safe house, or when he will be caught by the monster.
Input Format
The first line contains five integers .
The next lines each contain three integers , meaning there is an undirected edge of length between and .
Output Format
Two lines.
If Little A in the worst case can safely reach the safe house, output YES, and then on the next line output the distance from the monster to the safe house after Little A arrives at the safe house.
If Little A in the worst case cannot safely reach the safe house, output NO, and then on the next line output when Little A is caught by the monster.
If the answer on the second line is an integer, output the integer; otherwise output a decimal.
4 3 1 2 3
1 3 1
2 4 2
4 3 1
YES
1.5
4 3 1 2 3
1 3 2
2 4 2
4 3 1
NO
1
Hint
Explanation of “worst case”: The monster may have multiple possible ways to move. In other words, you need to consider every possible way the monster can move. As long as there exists some shortest-path movement strategy of the monster that can catch Little A, the answer is NO. The worst case means the monster chooses, among all its possible strategies, the one that can catch (or get close to) Little A the fastest.
Also, this problem does not have a special judge. That is, if the answer is an integer, you must output it exactly as an integer, without a decimal point. The testdata guarantees that there will be no answer with more than two decimal places.
Constraints
This problem uses bundled testcases.
$$\def\arraystretch{1.5} \begin{array}{c|c|c|c|c}\hline \textbf{~~Subtask~~}&\bm{~~n \le ~~}&\bm{~~~~m \le~~~~}& ~\textbf{~~Special Property~~}~&\textbf{~~Score~~}\cr\hline 0 &10 &20 & &10\cr\hline 1 &500 &1000 & &10\cr\hline 2 &800 &2000 & &10\cr\hline 3 &2\times10^5& &\text{A+B}&15 \cr\hline 4 &2\times10^5& &\text{A}&15 \cr\hline 5 &10^5 &2\times10^5& &20\cr\hline 6 &2\times10^5&2\times10^5& &20 \end{array}$$Special property : .
Special property : for each given , it satisfies .
For of the data, it is guaranteed that and , , the graph is connected, and there are no multiple edges.
Special Scoring Method
This problem uses subtask dependencies, as follows:
- For subtasks , you only need to solve subtask correctly to obtain the score of subtask .
- For subtask , you need to solve subtask correctly to obtain the score of subtask .
- For subtasks , you need to solve subtask correctly to obtain the score of subtask .
Attachment Note
Since many contestants got stuck on sub3 during the contest, a set of testdata within sub3 is provided here to help you check and fix your code.
Translated by ChatGPT 5