QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100 Difficulté: [afficher] Interactif

#4218. 隐藏图

Statistiques

存在一个具有 $n$ 个顶点的简单无向图。该图具有以下附加性质:

  • 任何导出子图都包含一个度数不超过 $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$)。连续的整数之间用空格分隔。然后刷新输出。

每次查询后,读取一行包含两个整数 $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$ 是图中的边数。接下来的 $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.