Universal Cup Judging System

Universal Cup

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show] Interactive
Statistics

題目描述

本題是一道互動題。

大海,又見面了。祝你下個暑假也幸福快樂!

很久很久以前,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.