#P6541. [WC2018] 即时战略
[WC2018] 即时战略
Description
Little M is playing a Real Time Strategy game. Unlike most similar games, the map of this game is a tree. That is, the map can be represented by a connected graph with nodes and edges. The nodes are numbered .
Each node has two possible states: "known" or "unknown". When the game starts, only node is known.
During the game, Little M can try to explore more nodes. Specifically, in each operation, Little M needs to choose a known node , and an arbitrary node different from (node may be unknown). Then the game's automatic pathfinding system will give the second node on the shortest path from to , i.e., the node adjacent to on the shortest path from to . At this time, if node is unknown, Little M will mark it as known.
The goal of the game is: using at most exploration operations, make all nodes become known. However, Little M is still a beginner at this game, and she hopes to get your help.
To make the game process easier, Little M provides you with an interactive library for this game; see "Task Description" and "Implementation Details".
Also, Little M provides some hints; see the last section "Hint".
Task Description
You need to implement a function play to help Little M achieve the goal.
play(n, T, dataType)nis the number of nodes in the tree.Tis the limit on the number of exploration operations.dataTypeis the data type of this test case; see "Constraints and Conventions".
In each test case, the interactive library will call the play function exactly once. Before it is called, the game is at the initial state.
You can call the function explore to help you explore more nodes in the game, but the number of calls to this function must not exceed .
explore(x, y)xis a known node.yis any node different from (it does not have to be known).- This function returns the index of the second node on the shortest path from node to node .
After the function play returns, the interactive library will check the game state: only if every node is known will the goal be considered completed.
Implementation Details
You must submit exactly one source file rts.cpp/c/pas implementing the above function, and follow the naming and interface below.
For C/C++ users:
The source code needs to include the header file rts.h (note that when submitting on Luogu, you do not need to include this header file).
The function play you need to implement:
void play(int n, int T, int dataType);
The interface of the function explore is:
int explore(int x, int y);
For Pascal users:
You need to use the unit graderhelperlib.
The function play you need to implement:
procedure play(n, T, dataType : longint);
The interface of the function explore is:
function explore(x, y : longint) : longint;
Input Format
The first line contains three integers , , . It is guaranteed that , , and or or .
The next lines each contain two integers , . It is guaranteed that and , representing an edge between and .
The input guarantees that these edges form a tree.
Output Format
The interactive library will judge whether the game goal is completed. If completed, it will output ; otherwise, it will output the corresponding error message.
4 100 1
1 3
3 4
3 2
Correct
Hint
Sample Explanation
This is the output file obtained using the grader in the problem directory and a correct program.
For this sample, one possible call sequence of the explore function is:
explore(1, 2), returns 3explore(3, 2), returns 2explore(2, 4), returns 3explore(3, 4), returns 4
How to Test Your Program
For C/C++ users:
In the problem directory, you need to compile to an executable using the following command:
g++ grader.cpp rts.cpp -o rts -O2
The executable will read input from standard input.
After reading is finished, the interactive library will call the play function. If at this time the number of times you call explore exceeds , the interactive library will output detailed error information and exit.
Then the interactive library will check whether the game goal is completed. If completed, it will output ""; otherwise, it will output the corresponding error message.
If the parameters passed to explore are invalid ( are not in the range to , or is not a known node, or ), then the interactive library will output detailed error information and exit.
If you want to test using your own input file, please ensure that the input file meets the above format requirements. Otherwise, the program is not guaranteed to run correctly.
How to Use the Sample Source Code
In the problem directory, there are sample source codes for each language: rts_sample.cpp/c/pas. Choose the language you need, copy it as rts.cpp/c/pas, and compile as described above to obtain an executable.
For unofficial participants, you can only choose one language to answer. That is, in the problem directory, you cannot have multiple versions of rts.cpp/c/pas in different languages at the same time; otherwise, the system will arbitrarily select one source file for judging and use it as the final result.
Next, you need to modify the implementation of this file to meet the requirements of the problem.
Subtasks
There are 20 test points in total, and each test point is worth 5 points.
For all test points and all samples, , , and or or .
The data types corresponding to different are as follows:
- For test points with , there are no special restrictions.
- For test points with , the game map is a complete binary tree rooted at node .
That is, there exists a permutation of ~ such that , and node () is connected by an edge to node . - For test points with , the game map is a chain.
That is, there exists a permutation of ~ such that node () is connected by an edge to node .
For each test point, the values of , , and are as follows:
| Test Point ID | |||
|---|---|---|---|
| 1 | 1 | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 2 | ||
| 6 | |||
| 7 | |||
| 8 | 3 | ||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | 1 | ||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 |
Hint
Here are some thoughtful tips from Little M:
- A graph (undirected graph) consists of nodes and edges. An edge is an unordered pair of nodes, used to describe the relationships between nodes.
- A path is a non-empty sequence of nodes such that there is an edge between every two adjacent nodes in the sequence.
- Two nodes are connected if and only if there exists a path that starts at one of them and ends at the other.
- A graph is connected if and only if every pair of nodes in the graph is connected.
- A tree with nodes is a connected graph with nodes and edges.
- The shortest path between two nodes means, among all possible paths connecting these two nodes, the one with the smallest sequence length.
- In a tree, the shortest path between any two nodes is unique.
- Gaining points by accessing input/output files, attacking the judging system, attacking the judging library, etc., is considered cheating, and the score obtained is invalid.
Translated by ChatGPT 5
京公网安备 11011102002149号