Logo
(追記) (追記ここまで)

29745번 - Closing Time 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB82221840.000%

문제

Hungary is a country with $N$ cities, numbered from 0ドル$ to $N - 1$.

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

  • $p_0 = a,ドル
  • $p_l = b,ドル
  • for each $i$ (0ドル ≤ i < l$), there is a road connecting cities $p_i$ and $p_{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 $p_0 , p_1 , \dots, p_t$ is the sum of the lengths of the $t$ 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 $K$. More precisely, for every $i$ between 0ドル$ and $N - 1,ドル inclusive, the closing time assigned to city $i$ is a nonnegative integer $c[i]$. The sum of all $c[i]$ must not be greater than $K$.

Consider a city $a$ and some assignment of closing times. We say that a city $b$ is reachable from city $a$ if and only if either $b = a,ドル or the path $p_0 , \dots , p_t$ between these two cities (so in particular $p_0 = a$ and $p_t = b$) satisfies the following conditions:

  • the length of the path $p_0, p_1$ is at most $c[p_1],ドル and
  • the length of the path $p_0, p_1, p_2$ is at most $c[p_2],ドル and
  • $\dots$
  • the length of the path $p_0 , p_1 , p_2 ,\dots , p_t$ is at most $c[p_t]$.

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

Note that if a city is reachable from city $X$ and reachable from city $Y,ドル 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.

구현

You should implement the following procedure.

int max_score(int N, int X, int Y, int64 K, int[] U, int[] V, int[] W)
  • $N$: the number of cities.
  • $X,ドル $Y$: the cities with main festival sites.
  • $K$: the upper bound on the sum of closing times.
  • $U,ドル $V$: arrays of length $N - 1$ describing road connections.
  • $W$: array of length $N - 1$ describing road lengths.
  • This procedure should return the maximum convenience score that can be achieved by some assignment of closing times.
  • This procedure may be called multiple times in each test case.

예제

Consider the following call:

max_score(7, 0, 2, 10, [0, 0, 1, 2, 2, 5], [1, 3, 2, 4, 5, 6], [2, 3, 4, 2, 5, 3])

This corresponds to the following road network:

Suppose the closing times are assigned as follows:

City 0ドル$ 1ドル$ 2ドル$ 3ドル$ 4ドル$ 5ドル$ 6ドル$
Closing time 0ドル$ 4ドル$ 0ドル$ 3ドル$ 2ドル$ 0ドル$ 0ドル$

Note that the sum of all closing times is 9ドル,ドル which is not more than $K = 10$. Cities 0ドル,ドル 1ドル,ドル and 3ドル$ are reachable from city $X$ ($X = 0$), while cities 1ドル,ドル 2ドル,ドル and 4ドル$ are reachable from city $Y$ ($Y = 2$). Therefore, the convenience score is 3ドル + 3 = 6$. There is no assignment of closing times with convenience score more than 6ドル,ドル so the procedure should return 6ドル$.

Also consider the following call:

max_score(4, 0, 3, 20, [0, 1, 2], [1, 2, 3], [18, 1, 19])

This corresponds to the following road network:

Suppose the closing times are assigned as follows:

City 0ドル$ 1ドル$ 2ドル$ 3ドル$
Closing time 0ドル$ 1ドル$ 19ドル$ 0ドル$

City 0ドル$ is reachable from city $X$ ($X = 0$), while cities 2ドル$ and 3ドル$ are reachable from city $Y$ ($Y = 3$). Therefore, the convenience score is 1ドル + 2 = 3$. There is no assignment of closing times with convenience score more than 3ドル,ドル so the procedure should return 3ドル$.

입력

출력

제한

  • 2ドル ≤ N ≤ 200,000円$
  • 0ドル ≤ X < Y < N$
  • 0ドル ≤ K ≤ 10^{18}$
  • 0ドル ≤ U[j] < V[j] < N$ (for each $j$ such that 0ドル ≤ j ≤ N - 2$)
  • 1ドル ≤ W[j] ≤ 10^6$ (for each $j$ such that 0ドル ≤ j ≤ N - 2$)
  • It is possible to travel from any city to any other city by using the roads.
  • $S_N ≤ 200,000円,ドル where $S_N$ is the sum of $N$ over all calls to max_score in each test case.

서브태스크

We say that a road network is linear if road $i$ connects cities $i$ and $i + 1$ (for each $i$ such that 0ドル ≤ i ≤ N - 2$).

번호배점제한
18

The length of the path from city $X$ to city $Y$ is greater than 2ドルK$.

29

$S_N ≤ 50,ドル the road network is linear.

312

$S_N ≤ 500,ドル the road network is linear.

414

$S_N ≤ 3,000円,ドル the road network is linear.

59

$S_N ≤ 20$

611

$S_N ≤ 100$

710

$S_N ≤ 500$

810

$S_N ≤ 3,000円$

917

No additional constraints.

힌트

샘플 그레이더

Let $C$ denote the number of scenarios, that is, the number of calls to max_score. The sample grader reads the input in the following format:

  • line 1ドル$: $C$

The descriptions of $C$ scenarios follow.

The sample grader reads the description of each scenario in the following format:

  • line 1ドル$: $N$ $X$ $Y$ $K$
  • line 2ドル + j$ (0ドル ≤ j ≤ N - 2$): $U[j]$ $V[j]$ $W[j]$

The sample grader prints a single line for each scenario, in the following format:

  • line 1ドル$: the return value of max_score

첨부

출처

Olympiad > International Olympiad in Informatics > IOI 2023 > Day 1 1번

  • 문제를 만든 사람: Hirotaka Yoneda, Masataka Yoneda

제출할 수 있는 언어

C++17, C++20, C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /