#P10070. [CCO 2023] Travelling Trader
[CCO 2023] Travelling Trader
Problem Description
A trader wants to do business between cities, transporting goods from one city to another to make a profit. There are cities, numbered . There are roads, each connecting two cities, and each road takes one day to travel. Using these roads, it is possible to reach any city from any other city.
If the trader is currently in city and chooses to do business, they can earn a profit of , but for each city, this profit can be earned at most once. The trader starts in city , travels along the roads to visit cities, and wants to maximize their total profit. However, if the trader goes too long without earning profit, their boss will become unhappy. Specifically, once the trader goes for more than consecutive days without earning any profit, the boss will fire them. Note: regardless of whether the trader does business in a city, moving between adjacent cities still takes one day. You need to find the maximum profit the trader can obtain and a route that achieves it.
Find the maximum possible total profit the trader can earn, and construct one valid plan.
Input Format
The first line contains two integers and , separated by spaces.
The next lines each contain two integers and , separated by spaces, describing a road.
The last line contains integers , meaning the profit gained by choosing to do business in the corresponding city.
Output Format
The first line outputs one integer, the maximum possible total profit.
The second line outputs one integer , the number of cities where the trader does business on an optimal route.
The third line outputs integers separated by spaces, meaning the cities where the trader does business in order on the optimal route, starting with .
If there are multiple correct solutions, you may output any of them.
4 1
1 2
1 3
2 4
3 1 4 1
7
2
1 3
5 2
1 2
1 3
2 4
2 5
3 1 4 1 5
14
5
1 4 5 2 3
Hint
Sample Explanation 1
On day , the trader starts in city and does business there, earning a profit of .
On day , the trader moves to city and does business there, earning a profit of .
On day , the trader cannot reach another city where they have not done business before being fired, so their total profit is .
Sample Explanation 2
The trader visits in the order , and can earn profit in every city.
Note that, to ensure they do not go more than days without earning profit, the trader delays doing business in city .
Constraints: for all testdata, , , , , .
| Subtask ID | Points | Range of | Range of |
|---|---|---|---|
| 1 | 8 | ||
| 2 | 28 | ||
| 3 | 12 | ||
| 4 | 16 | ||
| 5 | |||
| 6 | 20 |
Translated by ChatGPT 5