#P2349. 金字塔

金字塔

Description

A tomb raider sneaks into a pyramid to steal treasure. When she (could it be Lara Croft?) opens a treasure chest, a sudden puff of smoke appears (Pandora's box?). She quickly realizes the danger and decides to flee. Since she has the pyramid’s map, she hopes to find the best escape route. The map shows NN rooms. She is currently in room 11, and the exit is in room NN. She knows a secret: the smoke will halve her running speed in the corridor that directly connects some pair of rooms. She wants to find an escape route that minimizes the time used in the worst case.

Input Format

The first line contains two positive integers NN (3N1003 \le N \le 100) and MM (3M20003 \le M \le 2000).
Each of the following MM lines contains three positive integers UU, VV, and WW, indicating that running directly between room UU and room VV takes WW seconds (3W2553 \le W \le 255).

Output Format

Output the minimal possible time, in seconds.

7 8
1 2 10
2 3 12
3 4 20
4 7 8
1 7 34
2 5 10
5 6 12
6 4 13
66

Hint

Sample Explanation:

There are essentially three routes:

(1) 123471 \to 2 \to 3 \to 4 \to 7.
Total time: 10+12+20+8=5010 + 12 + 20 + 8 = 50. In the worst case, the segment 343 \to 4 takes twice as long, costing an extra 2020 seconds, so this route takes 7070 seconds in the worst case.

(2) 1256471 \to 2 \to 5 \to 6 \to 4 \to 7.
Total time: 10+10+12+13+8=5310 + 10 + 12 + 13 + 8 = 53. In the worst case, the segment 646 \to 4 takes twice as long, costing an extra 1313 seconds, so this route takes 6666 seconds in the worst case.

(3) 171 \to 7.
Total time: 34=3434 = 34. In the worst case, the segment 171 \to 7 takes twice as long, costing an extra 3434 seconds, so this route takes 6868 seconds in the worst case.

Translated by ChatGPT 5