#P13346. [EGOI 2025] Laser Strike
[EGOI 2025] Laser Strike
题目背景
You must choose C++20 to submit the problem.
题目描述
Ann and her friend Kathrin have recently discovered a new board game that has become their favourite: Laser Strike. In this game, the two players work together to remove pieces from the board. The game runs in two phases. The catch is that Kathrin will not have complete information about the game. In order to win the game, Ann and Kathrin have to work together, while communicating as little as possible.
There are unique pieces on the board, numbered from to . Both players can see these pieces. There are also connections between pairs of pieces, such that it is possible to reach any piece from any other piece by following these connections. In other words, these connections form a tree. Only Ann can see these connections; Kathrin does not know them.
In the first phase of the game, Ann decides on an order in which pieces should be removed, until there is only one left. This order will be kept secret from Kathrin. If she can replicate it, they will win the game. The removal of pieces must satisfy the following rule: every time a piece is removed, it must be connected with exactly one remaining piece. In other words, the removed piece must be a leaf of the tree formed by the remaining pieces and itself. (After the pieces have been removed, the last piece is removed automatically and the players win.) Ann must choose an order that corresponds to the above rule.
Ann will also write down a message to Kathrin, in the form of a binary string. Ann can choose how long this message is – but the shorter it is, the more points they get.
After that, the second phase of the game starts. The goal of the game is for Kathrin to remove pieces from the board in the order . She will make moves. Before move , Ann tells Kathrin a pair of integers with the following properties:
- ;
- there is still a pair of directly connected pieces with numbers and ; and
- either or is the correct piece that should be removed in this move.
Note that for Ann the connection is uniquely determined by the leaf in the current tree.
Kathrin then removes either or from the board. If this was the correct piece – that is, – they keep playing. Otherwise they lose the game.
Your task is to implement both Ann's and Kathrin's strategies so that they win the game.
Your program will be scored depending on the length of the message that Ann writes in the first phase of the game.
Implementation
This is a multi-run problem, meaning that your program will be executed twice. The first time it is run, it should implement Ann's strategy for the first phase of the game. After that, it should implement Kathrin's strategy for the second phase of the game.
The first line of the input contains two integers, and , where is either 1 or 2 (first or second phase), and is the number of pieces.
The following input depends on the phase:
Phase 1: Ann
After the first line (described above) the next lines of the input describe the tree. Each line contains two numbers, and (), indicating a connection between pieces and .
Your program should begin by outputting a binary string with at most 1000 characters, each 0 or 1, the message written by Ann. Note that to generate a string of length 0, it should output an empty line.
After this, it should output integers on separate lines, indicating the order in which Ann wants to remove the leaves of the tree. The order must be such that if the pieces are removed one by one from the tree in this order, the removed piece must always be a leaf, i.e., the tree must always remain connected.
Phase 2: Kathrin
After the first line (described above), the next line of input contains the binary string (Ann's message) from Phase 1.
After this, there will be rounds of interaction, one for each of Kathrin's moves.
In the th move, your program should first read two numbers, and (). One of these pieces is the leaf in Ann's order, and the other piece is the only remaining piece connected to . Then, your program should output , indicating that Kathrin removes this leaf. If your program does not print the correct leaf , the girls lose the game and your submission will be judged as Wrong Answer for this test case.
Details
If the sum of the running times of the two separate runs of your program exceeds the time limit, your submission will be judged as Time Limit Exceeded.
Make sure to flush standard output after printing each line, or else your program might be judged as Time Limit Exceeded. In Python, this happens automatically as long as you use input()
to read lines. In C++, cout << endl;
flushes in addition to printing a newline; if using printf, use fflush(stdout);
.
Note that correctly reading an empty string can be tricky. The provided templates handle this case correctly.
输入格式
See Implementation.
输出格式
See Implementation.
1 7
0 1
1 2
2 3
0 4
0 6
1 5
0110
5
3
2
6
4
0
2 7
0110
1 5
2 3
1 2
0 6
0 4
0 1
5
3
2
6
4
0
提示
Example
Note that the sample in this section has for simplicity and is therefore not a valid test case. Your program is not expected to be able to solve this case. All test cases on the grader will have .
In the sample, Ann is given the following tree. In the first phase, Ann reads the tree, selects a binary string "0110" to send to Kathrin, and also selects an order $[\ell_0, \ell_1, \ldots, \ell_{N-2}] = [5, 3, 2, 6, 4, 0]$ in which the pieces should be removed from the tree. In the second phase, Kathrin receives the string "0110" that was sent in the first phase. She then receives the pair and decides to remove vertex 5, which is indeed the leaf. For the next move, she receives the pair and removes the leaf 3, and so on. The following pictures depict the interactions:
Testing Tool
To facilitate the testing of your solution, we have provided a simple tool that you can download. See “attachments” at the bottom of the Kattis problem page. The tool is optional to use. Note that the official grader program on Kattis is different from the testing tool.
To use the tool, create an input file, such as “sample1.in”, which should start with a number followed by lines describing the tree, in the same format as in Phase 1. For example, for the sample below:
7
0 1
1 2
2 3
0 4
0 6
1 5
For Python programs, say solution.py (normally run as pypy3 solution.py
), run:
python3 testing_tool.py pypy3 solution.py < sample1.in
For C++ programs, first compile it (e.g. with g++ -g -O2 -std=gnu++23 -static solution.cpp -o solution.out
) and then run:
python3 testing_tool.py ./solution.out < sample1.in
Constraints and Scoring
- .
- for all connections.
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.
Group | Max score | Constraints |
---|---|---|
1 | 8 | The tree is a star. That is, all nodes except one are leaves. |
2 | 9 | The tree is a line. That is, all nodes except for two leaf nodes have exactly two adjacent nodes. |
3 | 21 | The tree is a star with lines going out from it. That is, all nodes have either one or two adjacent nodes, except for one that has more than two adjacent nodes. |
4 | 36 | The distance between any two nodes is at most 10. |
5 | 26 | No additional constraints. |
For every test group that your program solves correctly, you will receive a score based on the following formula:
$$\text{score} = S_g \cdot (1 - 0.3 \cdot \log_{10} \max(K, 1)) $$where is the maximum score for the test group, and is the maximum length of Ann's message needed for any test case in the test group. Your score for each test group will be rounded to the nearest integer.
The table below shows the number of points, for a few values of , that your program will get if it solves all test groups with that . In particular, to achieve a score of 100 points, your solution must solve every test case with .
K | 1 | 5 | 10 | 50 | 100 | 500 | 1000 |
---|---|---|---|---|---|---|---|
Score | 100 | 79 | 70 | 49 | 39 | 20 | 11 |