PivotOJ

Closing Time

시간 제한: 1000ms메모리 제한: 1024MB출처: IOI 2023BOJ 29745

문제

Hungary is a country with NN cities, numbered from 00 to N1N - 1.

The cities are connected by N1N - 1 bidirectional roads, numbered from 00 to N2N - 2. Road jj (0 ≤ j ≤ N - 2) connects city U[j]U[j] and city V[j]V[j] and has length T[j]T[j], that is, it allows one to travel between the cities in T[j]T[j] 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 aa and bb is a sequence of distinct cities p0,p1,,plp_0 , p_1 , \dots , p_l such that:

  • p0=ap_0 = a,
  • pl=bp_l = b,
  • for each ii (0 &le; i < l), there is a road connecting cities pip_i and pi+1p_{i+1}.

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 p0,p1,,ptp_0 , p_1 , \dots, p_t is the sum of the lengths of the tt 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 KK. More precisely, for every ii between 00 and N1N - 1, inclusive, the closing time assigned to city ii is a nonnegative integer c[i]c[i]. The sum of all c[i]c[i] must not be greater than KK.

Consider a city aa and some assignment of closing times. We say that a city bb is reachable from city aa if and only if either b=ab = a, or the path p0,,ptp_0 , \dots , p_t between these two cities (so in particular p0=ap_0 = a and pt=bp_t = b) satisfies the following conditions:

  • the length of the path p0,p1p_0, p_1 is at most c[p1]c[p_1], and
  • the length of the path p0,p1,p2p_0, p_1, p_2 is at most c[p2]c[p_2], and
  • \dots
  • the length of the path p0,p1,p2,,ptp_0 , p_1 , p_2 ,\dots , p_t is at most c[pt]c[p_t].

This year, the two main festival sites are located in city XX and city YY. 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 XX.
  • The number of cities reachable from city YY.

Note that if a city is reachable from city XX and reachable from city YY, 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.

코드를 제출하려면 로그인하세요.