QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Interactive

#7510. 独立集

Statistics

这是一个交互式问题。在打印每一行后,你必须执行刷新操作。例如,在 C 或 C++ 中可以使用 fflush(stdout),在 Java 中可以使用 System.out.flush(),在 Pascal 中可以使用 flush(output),在 Python 中可以使用 sys.stdout.flush()

图中的独立集是指一个顶点集合,使得集合中任意两个顶点之间都没有边相连。

有一个构造图中独立集的算法。该算法接收一个顶点序列。假设序列为 $a_1, a_2, \dots, a_\ell$。初始时,有一个空集 $S$ 和一个满足 $cnt_1 = cnt_2 = \dots = cnt_\ell = 0$ 的序列 $cnt_1, cnt_2, \dots, cnt_\ell$。

然后对于 $i$ 从 $1$ 到 $\ell$:

  • 查看图中的每一条边,每当边连接 $a_i$ 和 $S$ 中的一个顶点时,将 $cnt_i$ 增加 $1$(即 $cnt_i = cnt_i + 1$)。
  • 如果在搜索后 $cnt_i = 0$,则将 $a_i$ 插入到 $S$ 中。

显然,算法执行完毕后,$S$ 将是一个独立集。

现在,你只知道图中顶点的数量 $n$,你想要找出图中所有的边。有一个交互器可以帮助你。交互器接收一个顶点序列,运行上述算法,并返回序列 $cnt_1, cnt_2, \dots, cnt_\ell$。

你希望在所提供的序列总长度不超过 $176\,000$ 的前提下完成目标。

注意,图中可能存在重边和自环。

输入格式

第一行包含一个整数 $n$,表示图中的顶点数量。

假设 $m$ 是图中的边数。保证 $1 \le n \le 4000$ 且 $0 \le m \le 10\,000$。

交互

要向交互器提供序列 $a_1, a_2, \dots, a_k$,请打印一行格式为 “? k a1 a2 ... ak” ($k \ge 1$) 的内容。然后你应该读取一行答案,其格式为 “cnt1 cnt2 ... cntk”。

如果你已经找到了图中所有的边,请打印一行格式为 “! m x1 y1 x2 y2 ... xm ym” 的内容。边 $(x_1, y_1), (x_2, y_2), \dots, (x_m, y_m)$ 表示你的答案。你可以以任意顺序打印这些边。

在打印每一行后,你的程序必须执行刷新操作。

样例

输入格式 1

4
0 2 1 0 1 0
0 1 1 0 0

输出格式 1

? 6 1 2 3 1 3 4
? 5 4 4 4 2 3
! 4 1 2 1 2 1 3 4 4

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#604Editorial Open集训队作业 解题报告 by 祁沐笛Qingyu2026-01-02 22:57:33 Download

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.