#P17144. [NOI 2026] 木棉
[NOI 2026] 木棉
Background
The statement and sample attachments come from QOJ。
When submitting to Luogu, there is no need to include the header #include "kapok.h"。Just copy
std::vector<bool> kapok(
int c, int n, int m, std::vector<int> a, std::vector<int> l, std::vector<int> r, std::vector<int> x, std::vector<int> y
);
to the beginning of your program, and compile with a C++17 or higher compiler.
Problem Description
Those kapok trees in the old home are still growing in Little 's gradually blurred memories. Little 's memories of the old home can be represented by a sequence of length , 。
Each kapok tree in the old home is an unrooted tree with labeled nodes. Little 's impression of a kapok tree can be described by an interval of her old-home memory:
- This tree has nodes, with node labels 。
- $[\min(a_l,k-1),\min(a_{l+1},k-1),\ldots,\min(a_{r-1},k-1)]$ is the Prüfer sequence of this tree, where the definition of Prüfer sequence is given in the [Hint] section.
While recalling the past, Little also asked you queries. The -th query () is:
- On the kapok tree corresponding to the interval in the old-home memory, are nodes adjacent?
Implementation Details
Contestants do not need to, and should not, implement the main function.
Contestants need to ensure that the submitted source file includes the header kapok.h, i.e. add the following code at the beginning:
#include "kapok.h"
Contestants need to implement the following function in the submitted source file kapok.cpp:
std::vector<bool> kapok(
int c, int n, int m, std::vector<int> a, std::vector<int> l, std::vector<int> r, std::vector<int> x, std::vector<int> y
);
- represent the test point index, the length of the old-home memory sequence, and the number of queries, respectively. means this test point is a sample.
- is the old-home memory sequence.
- are the two endpoints of the interval given in each query.
- are the labels of the two nodes given in each query.
- This function needs to return a sequence of length exactly , , where () is the answer to the -th query.
- For each test point, this function will be called exactly once by the judge.
template_kapok.cppin this problem directory is the provided sample code. Contestants may refer to it and implement their own code.
Input Format
Test Program Method
Contestants can compile an executable in this problem directory using the following command:
g++ grader.cpp kapok.cpp -o kapok -O2 -std=c++14 -static
For the compiled executable kapok:
- The executable will read input from standard input in the following format:
- The first line contains three non-negative integers 。
- The second line contains non-negative integers 。
- The -th line () contains four non-negative integers 。
- The executable will output to standard output in the following format:
- The -th line () contains one non-negative integer, where means is
false, and means istrue。
- The -th line () contains one non-negative integer, where means is
Output Format
Hint
Sample Explanation
- The tree corresponding to interval has nodes, and its Prüfer sequence is . The edge set is . Therefore, nodes are adjacent.
- The tree corresponding to interval has nodes, and its Prüfer sequence is . The edge set is . Therefore, nodes are not adjacent.
- The tree corresponding to interval has nodes, and its Prüfer sequence is empty. The only edge is . Therefore, nodes are adjacent.
Sample
See kapok/kapok2.in and kapok/kapok2.ans in the contestants' directory.
This sample satisfies the constraints of test points 。
Sample
See kapok/kapok3.in and kapok/kapok3.ans in the contestants' directory.
This sample satisfies the constraints of test points 。
Constraints
For all testdata:
- 。
- For all , 。
- For all , and 。
::cute-table{tuack} | Test point index | | Special property | |:-:|:-:|:-:| | | | None | | | | ^ | | | | For all , | | | ^ | For all , | | | ^ | For all , | | | ^ | For all , | | | ^ | | | | ^ | For all , | | | | None | | | | ^ |
Special property : For all , after are given, are generated independently and uniformly at random from all ordered pairs of nodes that satisfy the limits.
0 8 3
2 0 2 6 0 7 2 2
0 3 0 2
3 5 1 2
0 0 0 1
1
0
1
Hint
Sample Explanation
- The tree corresponding to interval has nodes, and its Prüfer sequence is . The edge set is . Therefore, nodes are adjacent.
- The tree corresponding to interval has nodes, and its Prüfer sequence is . The edge set is . Therefore, nodes are not adjacent.
- The tree corresponding to interval has nodes, and its Prüfer sequence is empty. The only edge is . Therefore, nodes are adjacent.
Sample
See kapok/kapok2.in and kapok/kapok2.ans in the contestants' directory.
This sample satisfies the constraints of test points 。
Sample
See kapok/kapok3.in and kapok/kapok3.ans in the contestants' directory.
This sample satisfies the constraints of test points 。
Constraints
For all testdata:
- 。
- For all , 。
- For all , and 。
::cute-table{tuack} | Test point index | | Special property | |:-:|:-:|:-:| | | | None | | | | ^ | | | | For all , | | | ^ | For all , | | | ^ | For all , | | | ^ | For all , | | | ^ | | | | ^ | For all , | | | | None | | | | ^ |
Special property : For all , after are given, are generated independently and uniformly at random from all ordered pairs of nodes that satisfy the limits.
Hint
For an unrooted tree whose nodes are labeled ():
- Perform operations in order, where the -th operation () is:
- Find the current leaf with the smallest label 。
- Record the label of its unique adjacent node 。
- Then delete and its only incident edge from 。
- The resulting sequence of length , , is the Prüfer sequence of 。
Translated by ChatGPT 5