QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100 互動

#8871. 交互式重构

统计

这是一个交互式任务,你的程序将通过标准输入和输出与评测机进行通信。你的任务是重构一棵带有 $N$ 个节点和 $N-1$ 条边的带标号树。节点的标号为 $1$ 到 $N$。

你的程序可以进行若干次以下类型的查询:程序应输出一个由 $N$ 个字符组成的字符串,仅包含 $0$ 和 $1$,每个字符对应一个节点。评测机将返回一个包含 $N$ 个空格分隔整数的序列,其中第 $i$ 个整数表示第 $i$ 个节点的所有邻居节点对应的值(即查询字符串中的数字)之和。也就是说,如果节点 $j$ 是节点 $i$ 的邻居,那么查询字符串中第 $j$ 个数字就会计入评测机返回结果中第 $i$ 个数字的和。

请参阅下方的样例以获取说明。

输入格式

输入的第一行包含一个整数 $N$,表示树中的节点数。

之后,你的程序有两种选择:

  1. 输出 QUERY,紧跟一个空格,然后是一个由 $N$ 个 $0$ 和 $1$ 组成的字符串。
  2. 输出 ANSWER,换行,然后输出 $N-1$ 行,每行包含一对空格分隔的整数 $a, b$,表示节点 $a$ 和 $b$ 之间存在一条边。

如果你的程序输出了查询,评测机将返回一行包含 $N$ 个空格分隔整数的结果,每个整数对应一个节点。如果你的程序输出了答案,评测机将检查返回的树是否正确。

如果你的查询有误(格式错误或查询次数超限),评测机将输出 ERROR 而不是答案。

重要提示:请确保在输出后刷新缓冲区,并在输出答案后正确退出。是否实现对 ERROR 的处理由你决定。其目的是允许你的程序优雅地退出,并在出错时获得 WA(答案错误)判定,而不是 TLE(超出时间限制)。

数据范围

  • $2 \le N \le 3 \cdot 10^4$
  • 最多允许进行 $2 \uparrow\uparrow 3 = 2^{(2^2)} = 16$ 次查询。最终的答案输出不计入此限制。

样例

输入 1

5
0 0 1 2 0
1 1 0 0 1
0 0 0 1 0

输出 1

QUERY 10001
QUERY 00010
QUERY 10000
ANSWER
1 4
4 2
5 4
3 5

说明

题目中的树结构如下:

1-4-2
  |
  5-3

通过样例中的三次查询,可以唯一地重构出该树。

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.