Closing Time
시간 제한1초메모리 제한1024 MB
가중치가 있는 트리에서 닫는 시간의 합이 K 이하가 되도록 배정해, X와 Y에서 각각 도달 가능한 도시 수의 합을 최대로 만든다.
문제
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 length of a path is the sum of the lengths of the roads connecting consecutive cities along the path.
In Hungary, many people travel to attend the Foundation Day festivities in two major cities. Once the celebrations are over, they return to their homes. The government wants to prevent the crowd from disturbing the locals, so they plan to lock down all cities at certain times. Each city will be assigned a non-negative closing time by the government. The government has decided that the sum of all closing times must not be more than . More precisely, for every between and , inclusive, the closing time assigned to city is a nonnegative integer . The sum of all must not be greater than .
Consider a city and some assignment of closing times. We say that a city is reachable from city if and only if either , or the path between these two cities (so in particular and ) satisfies the following conditions:
- the length of the path is at most , and
- the length of the path is at most , and
- the length of the path is at most .
This year, the two main festival sites are located in city and city . For each assignment of closing times, the convenience score is defined as the sum of the following two numbers:
- The number of cities reachable from city .
- The number of cities reachable from city .
Note that if a city is reachable from city and reachable from city , it counts twice towards the convenience score.
Your task is to compute the maximum convenience score that can be achieved by some assignment of closing times.
제한
- (for each such that )
- (for each such that )
- It is possible to travel from any city to any other city by using the roads.
- , where is the sum of over all calls to max_score in each test case.
예제
이 문제는 공개된 예제가 없습니다.