The IOI 2023 organizers are in big trouble! They forgot to plan the trip to Ópusztaszer for the
upcoming day. But maybe it is not yet too late
There are
We say that the density of the road network at Ópusztaszer is at least
The organizers know a positive integer
The organizers can make calls to the phone dispatcher at Ópusztaszer to gather information
about the road connections between certain landmarks. In each call, two nonempty arrays of
landmarks
for each and such that ; for each and such that ; for each and such that and .
For each call, the dispatcher reports whether there is a road connecting a landmark from true
. Otherwise, the dispatcher returns false
.
A trip of length
Your task is to help the organizers to find a longest trip at Ópusztaszer by making calls to the dispatcher.
Implementation Details
You should implement the following procedure:
std::vector<int> longest_trip(int N, int D)
: the number of landmarks at Ópusztaszer. : the guaranteed minimum density of the road network.- This procedure should return an array
, representing a longest trip. - This procedure may be called multiple times in each test case.
The above procedure can make calls to the following procedure:
bool are_connected(std::vector<int> A, std::vector<int> B)
: a nonempty array of distinct landmarks. : a nonempty array of distinct landmarks. and should be disjoint.- This procedure returns
true
if there is a landmark from and a landmark from connected by a road. Otherwise, it returnsfalse
. - This procedure can be called at most
times in each invocation oflongest_trip
, and at most times in total. - The total length of arrays
and passed to this procedure over all of its invocations cannot exceed .
The grader is not adaptive. Each submission is graded on the same set of test cases. That is, the
values of longest_trip
within each test case.
Examples
Example 1
Consider a scenario in which

The procedure longest_trip is called in the following way:
longest_trip(5, 1)
The procedure may make calls to are_connected as follows.
Call | Pairs connected by a road | Return value |
---|---|---|
are_connected([0], [1, 2, 4, 3]) |
true |
|
are_connected([2], [0]) |
true |
|
are_connected([2], [3]) |
true |
|
are_connected([1, 0], [4, 3]) |
none | false |
After the fourth call, it turns out that none of the pairs
At this point, it can be concluded that longest_trip
may return

The procedure longest_trip
is called in the following way:
longest_trip(4, 1)
In this scenario, the length of a longest trip is longest_trip
may return one of
Example 2
Subtask
Constraints
- The sum of
over all calls tolongest_trip
does not exceed in each test case.
Subtasks
- (
points) - (
points) - (
points) . Let denote the length of a longest trip. Procedurelongest_trip
does not have to return a trip of length . Instead, it should return a trip of length at least . - (
points)
In subtask are_connected
over a single invocation of longest_trip
. Let longest_trip
over every test case of the subtask. Your score for this subtask is
calculated according to the following table:
Condition | Points |
---|---|
If, in any of the test cases, the calls to the procedure are_connected
do not conform to the
constraints described in Implementation Details, or the array returned by longest_trip
is
incorrect, the score of your solution for that subtask will be
Sample Grader
Let longest_trip
. The sample
grader reads the input in the following format:
- line
:
The descriptions of
The sample grader reads the description of each scenario in the following format:
- line
: - line
:
Here, each
- if landmarks
and are connected by a road, then the value of should be ; - if there is no road connecting landmarks
and , then the value of should be .
In each scenario, before calling longest_trip
, the sample grader checks whether the density of
the road network is at least Insufficient
Density
and terminates.
If the sample grader detects a protocol violation, the output of the sample grader is Protocol Violation: <MSG>
, where <MSG>
is one of the following error messages:
invalid array
: in a call toare_connected
, at least one of arrays and- is empty, or
- contains an element that is not an integer between
and , inclusive, or - contains the same element at least twice.
non-disjoint arrays
: in a call toare_connected
, arrays and are not disjoint.too many calls
: the number of calls made toare_connected
exceeds over the current invocation of longest trip, or exceeds in total.too many elements
: the total number of landmarks passed toare_connected
over all calls exceeds .
Otherwise, let the elements of the array returned by longest_trip
in a scenario be
- line
: - line
: - line
: the number of calls toare_connected
over this scenario
Finally, the sample grader prints:
- line
: the maximum number of calls toare_connected
over all calls tolongest_trip
Attachment Package
The sample grader along with sample test cases are available here.
Comments