| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 82 | 22 | 18 | 40.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:
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:
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:
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)
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ドル$.
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$).
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 8 | The length of the path from city $X$ to city $Y$ is greater than 2ドルK$. |
| 2 | 9 | $S_N ≤ 50,ドル the road network is linear. |
| 3 | 12 | $S_N ≤ 500,ドル the road network is linear. |
| 4 | 14 | $S_N ≤ 3,000円,ドル the road network is linear. |
| 5 | 9 | $S_N ≤ 20$ |
| 6 | 11 | $S_N ≤ 100$ |
| 7 | 10 | $S_N ≤ 500$ |
| 8 | 10 | $S_N ≤ 3,000円$ |
| 9 | 17 | 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:
The descriptions of $C$ scenarios follow.
The sample grader reads the description of each scenario in the following format:
The sample grader prints a single line for each scenario, in the following format:
max_scoreOlympiad > International Olympiad in Informatics > IOI 2023 > Day 1 1번
C++17, C++20, C++17 (Clang), C++20 (Clang)