Universal Cup Judging System

Universal Cup

Süre Sınırı: 2 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster] Etkileşimli
İstatistikler

题目描述

本题是一道交互题。

大海,又见面了。祝你下个暑假也幸福快乐!

很久很久以前,Una 和 Kamome 就已经是好朋友了。

图 1:Una 和 Kamome 在青岛旅行

她们喜欢玩猜谜游戏。上一次,Una 发明的游戏很快就被 Kamome 出色的策略破解了。这一次,Una 带来了一个新游戏。

Una 心里想了一棵有 $n$ 个节点的树。Kamome 最多可以进行 $n$ 次询问:

  • Kamome 可以告诉 Una 一个 $0 \sim n - 1$ 的排列 $p_1, p_2, \dots, p_n$,Una 会告诉 Kamome:如果将节点 $i$ 的权值设为 $2^{p_i}$,这棵树的带权直径长度是多少。

但有时候,Kamome 会发现 Una 在故意捣乱。更具体地说,有时无论询问多少次,她都无法唯一确定这棵树。在这种情况下,Kamome 可以直接报告无解。

交互格式

本题是一道交互题。请记得在每次输出后刷新输出缓冲区。刷新输出缓冲区可以使用:

  • C/C++ 中使用 fflush(stdout) 或 cout.flush();
  • Java 和 Kotlin 中使用 System.out.flush();
  • Python 中使用 sys.stdout.flush()。

首先,你需要读入一个整数 $T$($1 \le T \le 10^4$),表示测试数据的组数。

对于每组测试数据,你需要读入一个整数 $n$($2 \le n \le 100$,$\sum n^2 \le 10^6$),表示树的大小。

要发起一次询问,你需要输出一行格式为 ? p_1 p_2 ... p_n 的内容(满足 $0 \le p_i \le n - 1$,且对所有 $1 \le i < j \le n$ 有 $p_i \neq p_j$)。

随后,读入一个包含 $n$ 个字符的字符串,表示该树带权直径长度的二进制表示。如果你的询问不合法,或者在一组测试数据中进行了超过 $n$ 次询问,交互库将输出 $-1$。如果你的程序读到了 $-1$,必须立即退出以避免未定义行为。

如果你判定无法唯一确定这棵树,请输出 ! NO。

否则,你需要输出一行格式为 ! YES u_1 v_1 u_2 v_2 ... u_{n-1} v_{n-1} 的内容,表示这棵树包含边 $(u_i, v_i)$。你可以按任意顺序输出这些边。

接着,读入一个单词 OK 或 WA,表示你的回答是否正确。如果你的程序读到了 WA,必须立即退出以避免未定义行为。

如果这棵树本来无法被唯一确定,而你却输出了 YES,那么即便你输出的树恰好是正确的,你的回答也会被判为 Wrong Answer,因为 Una 会觉得你在作弊。

请注意,交互库是非自适应(not adaptive)的,即答案不会在你的询问过程中发生改变。

样例

样例输入 1

2
4
1110
1110
OK
3
111
OK

样例输出 1

? 0 1 2 3
? 2 1 0 3
! YES 1 4 2 4 3 4
? 0 1 2
! NO

样例解释

题目附件中提供了一个测试工具,以帮助选手开发和测试自己的程序。你可以从附件中下载该工具。使用 -h 选项运行该工具即可查看使用说明。测试工具仅实现了真实评测程序的一部分测试场景与一部分功能。

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.