Travelling Trader
시간 제한2초메모리 제한1024 MB
각 도시에 이익이 주어진 트리에서, 1번 도시에서 시작해 K일 넘게 이익을 늘리지 않고 이동하지 않는 경로 중 총이익이 최대인 경로를 구한다.
문제
A trader would like to make a business of travelling between cities, moving goods from one city to another in exchange for a profit. There are cities labelled and roads. Each road joins two cities and takes one day to traverse. It is possible to reach any city from any other city using these roads.
The -th city can give a profit of if the trader is currently in that city and chooses to do business in that city, but this profit may only be obtained once. The trader starts by doing business in city and wants to travel along the roads, visiting cities to maximize their total profit. However, the trader's boss will get unhappy and lay off the trader as soon as the trader goes more than days in a row without increasing their total profit. Note that the trader will take only one day to move between adjacent cities, regardless of whether the trader does business in either city. We would like to know the maximum profit the trader can make under this condition and a route that obtains this profit.
입력
The first line of input contains two space-separated integers and .
The next lines of input each contain two space-separated integers and , describing a road.
The last line of input contains integers , the profits given by choosing to do business in the corresponding city.
출력
On the first line, output the maximum possible total profit.
On the second line, output , the number of cities the trader does business in on an optimal route.
On the third line, output M space-separated integers , the cities the trader does business in on an optimal route in order, starting with .
If there are multiple possible correct outputs, any correct output will be accepted.