QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Difficulty: [show] Interactive

#4218. 隱藏圖

Statistics

有一個包含 $n$ 個頂點的簡單無向圖。該圖具有以下額外性質:

  • 任何誘導子圖(induced subgraph)中都存在一個度數(degree)至多為 $k$ 的頂點。

你需要找出這個隱藏圖。你可以檢查任意子集是否為獨立集。如果不是,我們將向你展示該誘導子圖內部的兩端點邊。

我們在互動過程中不會改變圖,因此你可以假設它是固定的。然而,我們可能會選擇誘導子圖中的任意一條邊來展示。換句話說,在所有測試中,圖是固定的,但互動器是自適應的。

你需要在至多 $2nk + n$ 次查詢內猜出該圖。

互動

互動開始時,輸入包含一個整數 $n$:隱藏圖中的頂點數量($2 \le n \le 2000$)。

整數 $k$ 未給出,但它滿足限制 $1 \le k < n$ 且 $nk \le 2000$。

之後,你可以進行查詢。

若要進行查詢,請輸出一行包含 “? $k$” ($1 \le k \le n$) 以及 $k$ 個不同的整數 $v_1, v_2, \dots, v_k$ ($1 \le v_i \le n$)。連續的整數之間請用單個空格分隔。然後重新整理(flush)輸出。

每次查詢後,讀取一行包含兩個整數 $i, j$。如果誘導子圖 $v_1, v_2, \dots, v_k$ 中沒有邊,則 $i = j = -1$;否則,$i \neq j$,$i \in \{v_1, \dots, v_k\}, j \in \{v_1, \dots, v_k\}$,且圖中存在一條連接 $i$ 和 $j$ 的邊。

當你找到圖時,第一行請輸出 “! $m$”。接下來的 $m$ 行應包含圖中邊的描述,每一行應包含兩個整數 $u, v$ ($1 \le u, v \le n$),表示由邊連接的頂點索引。

如果你的查詢次數超過 $2nk + n$,你的程式將會得到 Wrong Answer 或 Time Limit Exceeded。如果你沒有輸出任何內容或忘記重新整理輸出,你的程式將會得到 Idleness Limit Exceeded。

若要重新整理輸出,請在列印查詢和換行符後立即執行以下操作:

  • C++: fflush(stdout)cout.flush()
  • Java: System.out.flush()
  • Pascal: flush(output)
  • Python: stdout.flush()
  • 其他語言請參閱相關文件。

範例

輸入格式 1

3
1 2
2 3
1 3

輸出格式 1

? 2 1 2
? 2 2 3
? 2 1 3
! 3
1 2
2 3
1 3

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1012EditorialOpen题解Qiuly2026-02-14 01:41:30View

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.