luogu#P5060. 旅行

旅行

Background

jjcjjc really likes traveling (smy)!

Problem Description

NOIPNOIP 20182018 has ended, and jjcjjc decided to travel around the country. Each place has many “big shots”. He has a map to help him plan a route from location AA to location BB. The map has NN locations numbered from 11 to NN, and there are MM directed roads connecting different (or the same) locations.

Now, jjcjjc already knows how many “big shots” he will meet when taking the ii-th road directly from uiu_i to viv_i. He will write down the name of every “big shot” he meets (no matter whether the name has been written down before). However, each time he writes down one name, he needs to use one sticky note. Sticky notes are sold in bags, and each small bag that jjcjjc buys contains PP notes. jjcjjc does not want any sticky notes he buys to be wasted, so he wants every bag of notes he buys to be used up exactly when the trip ends. Besides that, jjcjjc is saving money for ......QwQ......QwQ, so he needs to spend less. Therefore, he wants this trip to use as few sticky notes as possible.

However, he does not know how to find the best route. As one of the “big shots”, can you help jjcjjc solve this problem and find the optimal path that satisfies the conditions?

Input Format

The first line contains five integers, in order: NN, MM, PP, the index of the start point AA, and the index of the end point BB.

Lines 22 to M+1M+1 describe the roads. Each line contains three integers: the start point index uiu_i and end point index viv_i of the ii-th road, and the number of “big shots” met on this road numinum_i.

Output Format

If there exists a route that satisfies the conditions, output two lines. The first line contains one integer, the total number of “big shots” met on the chosen optimal path. The second line outputs the detailed route of the optimal path from AA to BB. The testdata guarantees that the answer is unique.

If no such route exists, output one line containing the string “jjcjjc failsfails inin travellingtravelling” (without quotes).

2 2 3 1 2
1 2 1
2 2 1
3
1->2->2->2
4 6 3 2 3
2 1 7
2 4 0
4 3 6
1 4 0 
2 3 1
2 3 9
6
2->4->3
3 3 5 1 3
1 2 15
2 3 7
1 3 3 
jjc fails in travelling

Hint

This problem has 33 subtasks.

For 30%30\% of the testdata: 2N1002 \le N \le 100, 2M50002 \le M \le 5000, 1P501 \le P \le 50.

For another 20%20\% of the testdata: 2N5×1042 \le N \le 5 \times 10^4, M2×105M \le 2 \times 10^5, P=1P = 1.

For another 50%50\% of the testdata: 2N5×1042 \le N \le 5 \times 10^4, M2×105M \le 2 \times 10^5, 1P501 \le P \le 50.

For all testdata: 1A,B,ui,viN1 \le A, B, u_i, v_i \le N, 0numi1080 \le num_i \le 10^8.

By:By : Never Stop Learning.

Translated by ChatGPT 5