CF2196C1.Interactive Graph (Simple Version)
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the simple version of the problem. The difference between the versions is that in this version, you can ask no more than 32⋅(n+m) questions, and n≤15. You can hack only if you solved all versions of this problem.
This is an interactive problem.
The jury has thought of a directed acyclic graph without loops and multiple edges, which has n vertices and m edges.
Your task is to determine which edges are in this graph. To do this, you can ask questions of the form: what does the k-th path look like in the lexicographically∗ sorted list of all paths in the graph.
A path in the graph is a sequence of vertices u1,u2,…,ul, such that for any i<l, there exists an edge (ui,ui+1) in the graph.
Your task is to accomplish this by asking no more than 32⋅(n+m) questions.
∗A sequence a is lexicographically smaller than a sequence b if and only if one of the following holds:
- a is a prefix of b, but a=b; or
- in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
这是该问题的简单版本。两个版本的区别在于:在此版本中,你最多只能提出 32⋅(n+m) 个问题,且 n≤15。仅当你解决了该问题的所有版本后,才可进行 Hack。
这是一个交互式问题。
出题人构思了一个不含环和重边的有向无环图(DAG),该图包含 n 个顶点和 m 条边。
你的任务是确定该图中具体包含哪些边。为此,你可以提出如下形式的问题:图中所有路径按字典序∗排序后的列表中,第 k 条路径是什么?
图中的一条路径是指一个顶点序列 u1,u2,…,ul,使得对任意 i<l,图中均存在一条从 ui 指向 ui+1 的边。
你需要在至多 32⋅(n+m) 次提问内完成该任务。
∗ 序列 a 字典序小于序列 b 当且仅当满足以下条件之一:
- a 是 b 的真前缀(即 a 是 b 的前缀,但 a=b);或
- 在 a 与 b 首次出现差异的位置上,a 中对应位置的元素小于 b 中对应位置的元素。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10). The description of the test cases follows.
Each test case consists of a single line with an integer n (1≤n≤15) — the number of vertices in the graph.
The jury guarantees that the given graph does not contain cycles or multiple edges.
Note that m is unknown to you.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤10)。随后是测试用例的描述。
每个测试用例由一行组成,其中包含一个整数 n(1≤n≤15)——表示图中顶点的数量。
评测方保证所给图不含环或重边。
注意:m 的值对你未知。
输入输出样例
输入#1
3 5 1 1 2 1 2 3 1 2 4 3 1 2 5 2 1 3 3 1 3 4 3 1 3 5 1 2 1 3 1 4 1 5 1 0 2 1 1 1 2 2 2 1
输出#1
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ? 11 ? 14 ? 15 ! 6 1 3 1 2 2 4 3 4 2 5 3 5 ? 2 ! 0 ? 1 ? 2 ? 3 ! 1 2 1
说明/提示
The graph for the first test case.

In this graph, there are 15 paths, which are arranged in lexicographic order as follows:
- 1
- 1→2
- 1→2→4
- 1→2→5
- 1→3
- 1→3→4
- 1→3→5
- 2
- 2→4
- 2→5
- 3
- 3→4
- 3→5
- 4
- 5
第一个测试用例的图。

在此图中,共有 15 条路径,按字典序排列如下:
- 1
- 1→2
- 1→2→4
- 1→2→5
- 1→3
- 1→3→4
- 1→3→5
- 2
- 2→4
- 2→5
- 3
- 3→4
- 3→5
- 4
- 5
输入解题思路,AI测评打分。不知道怎么写?