Truck Driver
시간 제한4.5초메모리 제한1024 MB
가중치가 있는 트리에서 각 도시마다 배달 횟수가 정해져 있고, 하루마다 한 도시의 횟수가 바뀔 때 도시 0에서 출발해 도시 i를 정확히 W[i]번 방문하고 돌아오는 닫힌 경로의 최대 이동 시간을 구한다.
문제
Hungary is a country with cities numbered from to .
The cities are connected by bidirectional roads, numbered from to . Road () connects city and city and has length , that is, it allows one to travel between the cities in units of time. Each road connects two different cities, and each pair of cities is connected by at most one road.
A path between two distinct cities and is a sequence of distinct cities such that:
- ,
- ,
- for each (), there is a road connecting cities and .
It is possible to travel from any city to any other city by using the roads, that is, there is a path between every two distinct cities. Note that the path connecting any pair of cities is unique.
The distance of cities and is notated by and defined as follows:
- if then ,
- otherwise is the total length of the roads connecting consecutive cities in the path between and .
Karcsi is a truck driver who has to complete some number of deliveries in the cities. For each from to , inclusive, Karcsi has to complete deliveries in city . Karcsi starts from city , and he is allowed to complete the deliveries in any order, after which he returns to city . A delivery plan is a (possibly empty) sequence of cities, , such that for each () the sequence contains city exactly times.
The delivery time of a plan is the sum of the distances of consecutive cities in the sequence , that is, .
Karcsi has to work for days. At the start of each day, the number of required deliveries changes in one of the cities. For some city and nonnegative integer , the value of becomes . The value of remains as long as it is not modified again at the start of a day later on.
Karcsi gets paid by the hour. He wants to choose a delivery plan so that the delivery time is the maximum over all possible plans. Your task is to compute the maximum delivery time for each day when Karcsi has to work.
제한
- (for each such that )
- (for each such that )
- It is possible to travel from any city to any other city by using the roads.
- (for each such that )
예제
이 문제는 공개된 예제가 없습니다.