VK Cup 2017 - Round 2
E
Verifying Kingdom
Codeforces
3200
原题
← D→
翻译中…

This is an interactive problem.

翻译中…

The judge has a hidden rooted full binary tree with $*n*$ leaves. A full binary tree is one where every node has either $0$ or $2$ children. The nodes with $0$ children are called the leaves of the tree. Since this is a full binary tree, there are exactly $2*n* - 1$ nodes in the tree. The leaves of the judge's tree has labels from $1$ to $*n*$. You would like to reconstruct a tree that is isomorphic to the judge's tree. To do this, you can ask some questions.

翻译中…

A question consists of printing the label of three distinct leaves $*a*_{1}, *a*_{2}, *a*_{3}$. Let the depth of a node be the shortest distance from the node to the root of the tree. Let $*LCA*(*a*, *b*)$ denote the node with maximum depth that is a common ancestor of the nodes $*a*$ and $*b*$.

翻译中…

Consider $*X* = *LCA*(*a*_{1}, *a*_{2}), *Y* = *LCA*(*a*_{2}, *a*_{3}), *Z* = *LCA*(*a*_{3}, *a*_{1})$. The judge will tell you which one of $*X*, *Y*, *Z*$ has the maximum depth. Note, this pair is uniquely determined since the tree is a binary tree; there can't be any ties.

翻译中…

More specifically, if $*X*$ (or $*Y*$, $*Z*$ respectively) maximizes the depth, the judge will respond with the string "X" (or "Y", "Z" respectively).

翻译中…

You may only ask at most $10·*n*$ questions.

翻译中…

Input

翻译中…

The first line of input will contain a single integer $*n*$ ($3 ≤ *n* ≤ 1 000$) — the number of leaves in the tree.

翻译中…

Output

翻译中…

To print the final answer, print out the string "-1" on its own line. Then, the next line should contain $2*n* - 1$ integers. The $*i*$-th integer should be the parent of the $*i*$-th node, or -1, if it is the root.

翻译中…

Your answer will be judged correct if your output is isomorphic to the judge's tree. In particular, the labels of the leaves do not need to be labeled from $1$ to $*n*$. Here, isomorphic means that there exists a permutation $π$ such that node $*i*$ is the parent of node $*j*$ in the judge tree if and only node $π(*i*)$ is the parent of node $π(*j*)$ in your tree.

翻译中…

Interaction

翻译中…

To ask a question, print out three distinct integers $*a*_{1}, *a*_{2}, *a*_{3}$. These integers should be between $1$ and $*n*$, inclusive.

翻译中…

The judge will respond with a single character, either "X", "Y", "Z".

翻译中…

If the string is "X" (or "Y", "Z" respectively), that means the pair $(*a*_{1}, *a*_{2})$ (or $(*a*_{2}, *a*_{3})$, $(*a*_{3}, *a*_{1})$ respectively) has the deepest $*LCA*$ among the three pairs.

翻译中…

You may only ask a question at most $10·*n*$ times, otherwise, you will get Wrong Answer.

翻译中…

When you are ready to answer, print out a single integer "-1" on its own line. The next line should contain $2*n* - 1$ integers. The $*i*$-th integer should be the parent of the $*i*$-th node, or -1, if it is the root. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.

翻译中…

You will get Wrong Answer verdict if

翻译中…
  • Your question or answers are not in the format described in this statement.
  • You ask strictly more than $10·*n*$ questions.
  • Your question contains duplicate indices.
  • Your final answer is not isomorphic to the judge tree.
翻译中…

You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below).

翻译中…

To flush you can use (just after printing an integer and end-of-line):

翻译中…
  • fflush(stdout) in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • flush(output) in Pascal;
  • See the documentation for other languages.
翻译中…

If at any moment your program reads -1 as an answer, it should immediately exit normally (for example, by calling exit(0)). You will get Wrong Answer in this case, it means that you made more queries than allowed, or made an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

翻译中…

Hacking To hack someone, use the following format

翻译中…

n
p_1 p_2 ... p_{2n-1}

翻译中…

This denotes a tree where the parent of the $*i*$-th node is $*p*_{*i*}$ ($*p*_{*i*} =  - 1$ or $*n* < *p*_{*i*} ≤ 2*n* - 1$). If $*p*_{*i*}$ is equal to -1, then node $*i*$ is the root. This input must describe a valid full rooted binary tree.

翻译中…

Of course, contestant programs will not be able to see this input.

翻译中…

Note

翻译中…

For the first sample, the judge has the hidden tree:

翻译中…

image

翻译中…

Here is a more readable format of the interaction:

翻译中…

image

翻译中…

The last line can also be

翻译中…

8 6 9 8 9 7 -1 6 7

翻译中…

.

翻译中…

样例

Input #1
5
X
Z
Y
Y
X
Output #1
1 4 2
1 2 4
2 4 1
2 3 5
2 4 3
-1
-1 1 1 2 2 3 3 6 6
InputCopy OutputCopy
题目信息
题号
772E
时间限制
2 s
内存限制
256 MB
标签
二分
分治
交互题
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。