Closing Time
문제
Hungary is a country with cities, numbered from to .
The cities are connected by bidirectional roads, numbered from to . Road (0 ≤ j ≤ N - 2) 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 (0 ≤ i < l), 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.