#P6766. [APIO2020] 有趣的旅途
[APIO2020] 有趣的旅途
Description
In the largest theme park in Jakarta, there are attractions, numbered from to . These attractions are connected by bidirectional roads, and between any two attractions there is a unique simple path using these roads. The roads are numbered from to . Road connects attraction and attraction , and traversing this road takes one hour. To avoid congestion, each attraction is connected to at most three roads.
You want to find a touring route such that every attraction is visited exactly once. You think it is very boring if you have to pass too many roads when moving from one attraction to the next. To find an interesting route, you plan the visiting order so that the time needed to reach the next attraction is not greater than the time needed to reach the previous attraction. In other words, you want to find a sequence that contains every integer from to exactly once, and for , the time needed to go from attraction to attraction is not greater than the time needed to go from attraction to attraction .
You do not have the complete map of the park, so you must make some queries to the information center to find an interesting route. You can make at most queries. Each query provides two parameters and , where . Each query is one of the following:
-
How many hours are needed to travel from attraction to attraction . In particular, if , the answer is .
-
How many attractions satisfy that, when you want to travel from attraction to attraction , you must pass through attraction . Attraction is included in the count. In particular, if , the answer is .
You must implement the function createFunTour:
createFunTour(N, Q)- This function will be called by the grader exactly once.- : an integer representing the number of attractions.
- : an integer representing the maximum number of queries.
- This function may call the following two interactive functions:
hoursRequired(X, Y)- : an integer representing the index of the first attraction.
- : an integer representing the index of the second attraction.
- This function returns an integer representing the number of hours needed to travel from attraction to attraction .
- If the value of or is not in the range to , this test will be judged as Wrong Answer.
attractionsBehind(X, Y)- : an integer representing the index of the first attraction.
- : an integer representing the index of the second attraction.
- This function returns an integer representing how many attractions satisfy that, when you want to travel from attraction to attraction , you must pass through attraction .
- If the value of or is not in the range to , this test will be judged as Wrong Answer.
- This function must return an integer sequence of length , representing the visiting order of attractions that you found.
Input Format
The sample grader reads input in the following format:
N Q
A[0] B[0]
A[1] B[1]
.
.
.
A[N-2] B[N-2]
Output Format
If createFunTour correctly returns a sequence that satisfies the statement, and the total number of calls to hoursRequired and attractionsBehind does not exceed , then the sample grader will output the sequence returned by createFunTour. Otherwise, the sample grader will output an error message.
7 400000
0 1
0 5
0 6
1 2
1 4
2 3
3 6 4 5 2 0 1
Hint
In the example in the figure below, , , , and .

The grader will call createFunTour(7, 400000).
- If you query
hoursRequired(3, 5), the function will return . - If you query
hoursRequired(5, 4), the function will return . - If you query
attractionsBehind(5, 1), the function will return . From the -th attraction to the -st, -nd, -rd, and -th attractions, you must pass through the -st attraction. - If you query
attractionsBehind(1, 5), the function will return . - One valid returned sequence is , and the required times to reach the next attraction in order are .
Constraints
- .
- .
- Any two attractions can reach each other through bidirectional roads.
- Each attraction is connected to at most three roads.
Subtask ( points)
- .
Subtask ( points)
- .
Subtask ( points)
- For all , there is a bidirectional road connecting attraction and attraction .
Subtask ( points)
There exists at least one attraction such that for all , hoursRequired(T, i) , and there exists an integer interval satisfying the following conditions:
-
Traveling from attraction to attraction must pass through attraction if and only if .
-
If , then there is exactly one attraction such that:
- .
- There is a road connecting attraction and attraction .
-
If , then there is exactly one attraction such that:
- .
- There is a road connecting attraction and attraction .
Subtask ( points)
- No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号