#P13853. [CERC 2023] Interactive Reconstruction[Can't judge yet]

    ID: 15653 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023交互题Special Judge位运算构造ICPCCERC

[CERC 2023] Interactive Reconstruction[Can't judge yet]

题目描述

This is an interactive task where your program will communicate with a grader through standard input and output. Your task is to reconstruct a labelled tree with NN nodes and N1N-1 edges. Nodes are labelled from 11 to NN.

Your program is allowed to make a few queries of the following type: Your program should print a string of NN characters, consisting only of zeros and ones, one corresponding to each node. The grader will return a sequence of NN space-separated integers, the ii-th representing the sum of the values (i.e. digits of the query string) of all neighbours of the ii-th node. That is, if node jj is a neighbour of node ii, then the jj-th digit of the query string counts towards the sum in the ii-th number of the grader’s answer.

See the example below for an illustration.

Input and output data

The first input line will contain the number NN, the number of nodes in the tree.

Your program then has two options:

  1. Print "QUERY" (without quotation marks), a space, and a string of NN zeros and ones.
  2. Print "ANSWER" (without quotation marks), a newline, and N1N-1 lines, each containing a pair of space-separated integers a,ba, b, indicating that there exists an edge between nodes aa and bb.

If your program prints a query, this will be followed by the grader returning a line with NN space-separated integers, one per node. If your program prints an answer, the grader will check the returned tree for correctness.

If there was a mistake in your queries, either due to incorrect formatting or due to an exceeded number of queries, the grader will print “ERROR” (no quotation marks) instead of the answer.

Important: Ensure that your program flushes its output after printing and correctly exits after printing the answer. It is up to you whether to implement the ERROR handling. Its purpose is to allow your program to exit gracefully and get a WA instead of a TLE verdict in the case of an error.

Input limits

  • 2N31042 \leq N \leq 3 \cdot 10^{4}
  • At most 23=2(22)=162 \uparrow \uparrow 3 = 2^{(2^{2})} = 16 queries are allowed. The final answer does not count toward this restriction.
5

0 0 1 2 0

1 1 0 0 1

0 0 0 1 0

QUERY 10001

QUERY 00010

QUERY 10000

ANSWER
1 4
4 2
5 4
3 5

提示

Comment

The tree in question is the following one:

1-4-2
  |
  5-3

With the three queries in the example, it is possible to reconstruct it uniquely.