아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Travelling Trader

시간 제한2초메모리 제한1024 MB

요약
각 도시에 이익이 주어진 트리에서, 1번 도시에서 시작해 K일 넘게 이익을 늘리지 않고 이동하지 않는 경로 중 총이익이 최대인 경로를 구한다.
난이도

보통10점 중 7점

유형
트리, 동적 계획법, DFS, 그리디
정답자
아직 제출이 없습니다

문제

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 NN cities labelled 1,…,N1, \ldots, N and N−1N - 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 ii-th city can give a profit of p_ip\_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 11 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 KK 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 NN and KK.

The next N−1N - 1 lines of input each contain two space-separated integers u_iu\_i and v_iv\_i (1≤u_i,,v_i≤N,,u_i≠v_i)(1 \le u\_i,\\,v\_i \le N,\\,u\_i \neq v\_i), describing a road.

The last line of input contains NN integers p_1,…,p_Np\_1, \ldots, p\_N (1≤p_i≤109)(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 MM (1≤M≤N)(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,…,x_Mx\_1, \ldots, x\_M, the cities the trader does business in on an optimal route in order, starting with x_1=1x\_1 = 1.

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

제한

  • 2≤N≤200,0002 \le N \le 200\\,000
  • 1≤K≤31 \le K \le 3

예제2

  1. 예제 1

    입력
    4 1
    1 2
    1 3
    2 4
    3 1 4 1
    
    예상 출력
    7
    2
    1 3
    
  2. 예제 2

    입력
    5 2
    1 2
    1 3
    2 4
    2 5
    3 1 4 1 5
    
    예상 출력
    14
    5
    1 4 5 2 3