0% found this document useful (0 votes)
62 views4 pages

d1 Closing ISC

The document describes a problem involving finding the maximum "convenience score" achieved by assigning closing times to cities, given a road network connecting cities. The convenience score is defined as the number of cities reachable from two main festival sites. The task is to implement a procedure that returns the maximum convenience score possible, given parameters describing the road network and an upper bound on the total closing time assigned. Examples are provided to illustrate the problem and how to calculate the convenience score for a given closing time assignment. Constraints on the input parameters and subtasks of increasing difficulty are also described.

Uploaded by

Haidar Kasem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views4 pages

d1 Closing ISC

The document describes a problem involving finding the maximum "convenience score" achieved by assigning closing times to cities, given a road network connecting cities. The convenience score is defined as the number of cities reachable from two main festival sites. The task is to implement a procedure that returns the maximum convenience score possible, given parameters describing the road network and an upper bound on the total closing time assigned. Examples are provided to illustrate the problem and how to calculate the convenience score for a given closing time assignment. Constraints on the input parameters and subtasks of increasing difficulty are also described.

Uploaded by

Haidar Kasem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

closing

IOI 2023 Day 1 Tasks


English (ISC)

Closing Time
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. For each j such
that 0 ≤ j ≤ N − 2, road j connects city U [j] and city V [j] and has length W [j], that is, it allows
one to travel between the cities in W [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 p0 , p1 , … , pt of distinct cities, such that:

p0 = a,
pt = b,
for each i (0 ≤ i < t), there is a road connecting cities pi and pi+1 .

It is possible to travel from any city to any other city by using the roads, that is, there exists a path
between every two distinct cities. It can be shown that this path is unique for each pair of distinct
cities.

The length of a path p0 , p1 , … , pt 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 p0 , … , pt between these two cities (so in particular p0 = a
and pt = b) satisfies the following conditions:

the length of the path p0 , p1 is at most c[p1 ], and


the length of the path p0 , p1 , p2 is at most c[p2 ], and

the length of the path p0 , p1 , p2 , … , pt is at most c[pt ].

closing (1 of 4)
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.

Implementation Details

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.

Example

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:

closing (2 of 4)
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

closing (3 of 4)
convenience score more than 3, so the procedure should return 3.

Constraints

2 ≤ N ≤ 200 000
0≤X <Y <N
0 ≤ K ≤ 1018
0 ≤ U [j] < V [j] < N (for each j such that 0 ≤ j ≤ N − 2)
1 ≤ W [j] ≤ 106 (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.
SN ≤ 200 000, where SN is the sum of N over all calls to max_score in each test case.

Subtasks

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 points) The length of the path from city X to city Y is greater than 2K .
2. (9 points) SN ≤ 50, the road network is linear.
3. (12 points) SN ≤ 500, the road network is linear.
4. (14 points) SN ≤ 3 000, the road network is linear.
5. (9 points) SN ≤ 20
6. (11 points) SN ≤ 100
7. (10 points) SN ≤ 500
8. (10 points) SN ≤ 3 000
9. (17 points) No additional constraints.

Sample Grader

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

closing (4 of 4)

You might also like