| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 6 초 | 2048 MB | 0 | 0 | 0 | 0.000% |
THIS IS AN INTERACTIVE PROBLEM
Given a quintuple $(T, I, S_{V} , S_{E}, \iota)$ where:
$T$ is a rooted tree of n points $T = (V, E),ドル where $V$ is the set of points of $T$ and $E$ is the edge set of $T$. The nodes of the tree are numbered 1,ドル 2, \ldots , n,ドル where the root node is numbered 1ドル$.
$I$ is a set, and the elements in the set are called information. There are two different special elements: the UNIT element $\epsilon$ and the ILLEGAL element $\perp$.
For general information, it has two attributes: VERTEX SET and EDGE SET. For the special case of the identity element, it only has edge set attribute, while for the illegal information, it does not have either of these two attributes.
For information $o \in I \setminus \{\epsilon, \perp\}$ (the difference $A \ B$ of two sets A, B is defined as $A \ B = \{ x \in A \mid x \notin B\}$), the VERTEX SET of $o$ is a size two subset of V, denoted $S_{V}(o)$. That is, $SV(o) \subseteq V$ and $|SV(o) |=2$.
For information $o \in I \setminus \{\perp\},ドル the EDGE SET o is a subset of E, denoted $S_{E}(o),ドル such that $S_{E}(o) \subseteq E$. Define the edge set of the identity element is empty, that is, $S_E(\epsilon ) = \emptyset$.
For any edge $e \in E$ in the tree, denote $e = (u, v),ドル there is an information about $e,ドル $\iota(e) \in I,ドル which takes its endpoints its VERTEX SET and the edge itself as its EDGE SET, that is, $S_{V}(\iota(e)) = {u, v},ドル and $S_{E}(\iota(e)) = {e}$.
There are two ways that information get combined. Denote them as R and C. They have the following properties
For all $a, b \in I,ドル shorthand $r = R(a, b),ドル $c = C(a, b),ドル such that $r, c \in I$.
Combining UNIT with any general information gives the other. That is if $a = \epsilon,ドル then $r = c = b$; If $b = \epsilon,ドル then $r = c = a$.
Combining ILLEGAL with ANY information results in illegal information. That is, if $a = \perp$ or If $b = \perp,ドル then $r = c = \perp$.
For the remaining cases, if the intersection of the EDGE SET of the two information is non-empty, or the intersection of the POINT SET of the two information has size that's not 1, the combine results in ILLEGAL. That is, if $S_E(a) \cap S_E(b) \neq \emptyset$ or $|S_V (a) \cap S_V (b)| \neq 1,ドル then $r = c = \perp$.
Otherwise, the operations are specified as
where $\oplus$ represents the symmetric difference operation of sets, that is, $A \oplus B = (A \cup B) \setminus (A \cap B)$.
Define the on-tree distance of two points in $T$ as the number of edges on the tree that a unique simple path traversed by two points as endpoints.
Given the scoring parameter $M$ and $q$ queries, each query consisting a vertex $u$ of the tree and a non-negative integer $d$. Denote $X$ to be the set of all vertices in $T$ whose distances to $u$ in the tree does not exceed $d,ドル and $Y = \{ (a, b) \in E \mid a, b \in X\}$ to be the set of edges inside $X$.
It can be shown that starting from $\epsilon$ and all $L(e)$ ($e \in E$), a finite number of R, C calls produces an information $o$ such that $o \neq \perp$ and $S_{E}(o) = Y$. In particular, if $d = 0,ドル you the output should be the UNIT element $\epsilon$.
In each set of queries, you need to construct an information $o$ that satisfies this requirement, subject to the limit that the sum of the calls to $R$ and $C$ does not exceed $M$.
Files can be found here.
Make sure you #include count.h at the beginning of your program. The header file count.h implements the following:
info corresponding to the information;info type constant emptyinfo corresponding to $\epsilon,ドル which you can use directly in the program.
1 info MR(info a, info b);
2 info MC(info a, info b);
The two functions return the information corresponding to $R(a, b)$ and $C(a, b),ドル respectively. You need to ensure that calling $R(a, b)$ or $C(a, b)$ does not result in $\perp,ドル otherwise the program may behave unexpectedly.
bool isempty(info a);
This function returns true if and only if a is an identity element. See the reference interaction library for more implementation details.You do not need to, and should not, implement main();
You need to implement the following functions:
void init(int T, int n, int q, vector<int> fa, vector<info> e, int M)
info ask(int u, int d);
When testing, at each test case, the interactive library will call the init function exactly once, and then call the ask function $q$ times. The interactive library will use a special implementation, a single info type variable will constantly consume 12ドル$ bytes of memory,
It is guaranteed that under the condition that the number of calls is satisfied and the isempty function is not called, the time required for the interactive library to run in the final test does not exceed 0ドル.6$ seconds, and the memory consumed by the interactive library itself does not exceed 16 MiB. It is guaranteed that the final tested interactive library will take no more than 0ドル.25$ seconds to run with at most 10ドル^{8}$ isempty function calls.
A file named count.cpp is included in the issued files: you may use it.
The reference materials provides of two interactive libraries grader.o and checker.o are provided in this topic directory, which are linkable files generated by compiling two different interactive libraries. The implementation of the interaction library used in the final test is different from this implementation, so the solution of the contestant should not depend on the specific implementation of the interaction library, nor should it depend on the specific implementation of the info type in count.h.
You need to modify the distributed count.h to help with linking. Specifically, when linking the source code count.cpp with the program grader.o, you need to comment out the 5th line of the count.h code and keep the 4th line of code. Linking the checker.o method is similar, you need to comment out the 4th line of the count.h code and keep the 5th line of code. Players can modify the implementation of count.h by themselves to compile different programs.
After modification, the contestant can use the following command to compile the executable program in the directory of this question:
g++ count.cpp ‐c ‐O2 ‐std=c++14 ‐lm && g++ count.o grader.o ‐o count
g++ count.cpp ‐c ‐O2 ‐std=c++14 ‐lm && g++ count.o checker.o ‐o count
The first command line will compile the current count.cpp and link it with grader.o to generate the executable file count. The second line command will compile the current count.cpp and link it with checker.o to generate the executable file count.
The executable file count obtained by compiling the above method runs as follows:
After being read in, the interactive library is tested. If your program does not meet the interactive library limit, the output will return the corresponding error. Otherwise, for the linked executable, the output is as follows:
grader.o : It does not check whether the information returned by the ask function is correct at runtime, but it can help players determine whether the interaction meets the requirements. The running time of this program is closest to the interactive library at the time of evaluation, so players can use this program to test the running speed, but the correctness of the program is not guaranteed.checker.o : It will check whether the information returned by the ask function is correct at runtime, and can also help players determine whether the interactive operation meets the requirements. At the same time, it will check whether the information returned by the ask function is correct. This program can check the correctness of the answers.See count{1,2,3,4}.{in, ans}
Samples 2 & 3 satisfy special properties A and B (see below) respectively
NOTE:
info is not guaranteed to be emptyinfo.info, otherwise it will be regarded as attacking the interactive library.MR and MC functions before the init function call, otherwise undefined behavior may occur.info type variables returned by the interactive library. Trying to access other spaces may result in compilation errors or runtime errors.This question will first be subject to the same restrictions as traditional questions. For example, compilation errors will result in 0 points for the entire question, and runtime errors, exceeding the time limit, exceeding the space limit, etc. will result in 0 points for the corresponding test points, etc. In addition to the above conditions, a test point will receive a score of 0 if the program executes an illegal function call or gives an incorrect answer in a query operation. Otherwise, denote $C1$ and $C3$ as the number of times your program calls the interactive library function in the init function, and the maximum number of times your program calls the interactive library function in all q ask functions. If $C1 \leq 3 · 10^{7}$ and $C3$ does not exceed the scoring parameter $M$ for that test point, you will get a score for that test point, otherwise you can't get a score for that test point. Note: When calculating $C1$ and $C3,ドル only the number of calls of the MR and MC functions will be counted, but not the number of calls of the isempty function.
For all test cases, 1ドル \leq n \leq 2 \times 10^5,ドル 1ドル \leq q \leq 10^6,ドル for each query, 1ドル \leq u \leq n,ドル 1ドル \leq d \leq n-1$.
| TestCase | $n=$ | $q=$ | Property | $M=$ |
|---|---|---|---|---|
| 1ドル$ | 1000ドル$ | 10ドル^4$ | 500ドル$ | |
| 2ドル$ | 2000ドル$ | 10ドル^4$ | 500ドル$ | |
| 3,4ドル$ | 10ドル^5$ | 10ドル^6$ | A | 5ドル$ |
| 5,6ドル$ | 6ドル \times 10^4$ | 6ドル\times 10^4$ | B | 50ドル$ |
| 7ドル$ | 6ドル \times 10^4$ | 6ドル \times 10^4$ | B | 5ドル$ |
| 8ドル$ | 10ドル^5$ | 10ドル^5$ | B | 5ドル$ |
| 9ドル$ | 7500ドル$ | 5ドル \times 10^4$ | C | 500ドル$ |
| 10ドル$ | 10ドル^4$ | 5ドル \times 10^4$ | 500ドル$ | |
| 11ドル$ | 1ドル.5 \times 10^4$ | 5ドル \times 10^4$ | 500ドル$ | |
| 12ドル$ | 2ドル \times 10^4$ | 5ドル \times 10^4$ | 50ドル$ | |
| 13ドル$ | 2ドル.5 \times 10^4$ | 5ドル \times 10^4$ | 5ドル$ | |
| 14ドル$ | 3ドル \times 10^4$ | 10ドル^5$ | 5ドル$ | |
| 15ドル$ | 6ドル \times 10^4$ | 10ドル^6$ | D | 5ドル$ |
| 16ドル$ | 6ドル \times 10^4$ | 10ドル^6$ | 5ドル$ | |
| 17ドル$ | 8ドル \times 10^4$ | 10ドル^6$ | 5ドル$ | |
| 18ドル$ | 10ドル^5$ | 10ドル^6$ | 5ドル$ | |
| 19ドル$ | 1ドル.5 \times 10^5$ | 10ドル^6$ | 5ドル$ | |
| 20ドル$ | 2ドル \times 10^5$ | 10ドル^6$ | 1ドル$ |
C++17, C++20, C++17 (Clang), C++20 (Clang)