QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 1024 MB 満点: 100 インタラクティブ

#4919. Tree

統計

This is an interactive problem.

There is a tree with $n$ nodes rooted at $1$. For each query, you provide a set $T$. Let $S_u$ denote the set of nodes in the subtree of $u$, and $d(u, v)$ denote the number of edges on the path between $u$ and $v$. The interactor returns:

$$V=\{x \mid \exists u\in T,x\in S_u\}\\D(T)=\sum_{i\in V,j\in V,i < j}d(i,j)$$

If the tree you return is isomorphic to the actual tree, you will receive $40\%$ of the points.

Implementation Details

You need to implement std::vector<int> solve(int n);, where $n$ is the number of nodes. The returned vector should store the parent of each node from $2$ to $n$ in order. Note: It is not guaranteed that the parent's index is smaller than the child's index.

You can use int query(std::vector<int> T); to perform a query as described above.

During official evaluation, the interactor only includes anti-cheating measures; its efficiency is the same as the provided file.

For local testing, the interactor reads: the first line contains an integer $n$, and the second line contains $n-1$ integers representing the parents of nodes $2$ to $n$, respectively.

Examples

Input 1

6
1 2 3 1 2

Output 1

query({1})=31
query({3,5})=8
query({3})=1

Note

{1,2,3,1,2}:  score=1.0
{1,2,3,2,1}:  score=0.4
{1,1,1,1,1}:  score=0.0

Constraints and Subtasks

$n\le 1000$, where $T$ represents the upper bound on the number of queries.

  • A: The tree is a binary tree.
  • B: The tree is random. The generation method is: generate a random permutation $p$ such that $p_1=1$, then for each $i$, choose the parent $f_{p_i}$ uniformly at random from $\{p_1, \dots, p_{i-1}\}$.
$n$ $T$ Score Special Property
$5$ $1\,000$ $5$
$100$ $10^5$ $5$
$5\,000$ $10$
$1\,000$ $2\times 10^5$ $10$
$10^5$ $10$ A
$10$ B
$10$
$5 \times 10^4$ $10$ A
$10$ B
$10$
$3 \times 10^4$ $10$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.