Logo
(追記) (追記ここまで)

28321번 - Travelling Trader 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB1811880.000%

문제

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 $N$ cities labelled 1,ドル \ldots, N$ and $N - 1$ 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 $i$-th city can give a profit of $p_i$ 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 1ドル$ 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 $K$ 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 $N$ and $K$.

The next $N - 1$ lines of input each contain two space-separated integers $u_i$ and $v_i$ $(1 \le u_i,,円v_i \le N,,円u_i \neq v_i),ドル describing a road.

The last line of input contains $N$ integers $p_1, \ldots, p_N$ $(1 \le p_i \le 10^9),ドル 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 $M$ $(1 \le M \le N),ドル the number of cities the trader does business in on an optimal route.

On the third line, output M space-separated integers $x_1, \ldots, x_M,ドル the cities the trader does business in on an optimal route in order, starting with $x_1 = 1$.

If there are multiple possible correct outputs, any correct output will be accepted.

제한

  • 2ドル \le N \le 200,000円$
  • 1ドル \le K \le 3$

예제 입력 1

4 1
1 2
1 3
2 4
3 1 4 1

예제 출력 1

7
2
1 3

On day 1ドル,ドル the trader starts by doing business in city 1ドル,ドル making a profit of 3ドル$.

On day 2ドル,ドル the trader moves to city 3ドル$ and does business there, making a profit of 4ドル$.

At this point, the trader cannot reach another city in which they have not done business before getting laid off, so their total profit is 7ドル$.

예제 입력 2

5 2
1 2
1 3
2 4
2 5
3 1 4 1 5

예제 출력 2

14
5
1 4 5 2 3

The trader can make a profit in every city by visiting them in the order 1,ドル 2, 4, 2, 5, 2, 1, 3$.

Note that the trader strategically delays doing business in city 2ドル$ to ensure they do not go more than 2ドル$ days without making a profit.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCO 2023 5번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /