QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9291. 高效拦截

Statistics

Berland 王国宏伟壮丽,但目前由一位强大而乖戾的国王 Vlad 统治。他年事已高,如今看谁都觉得在密谋叛乱。他怀疑自己的两个儿子正在策划政变,因此决定建立对他们所有通信的控制。

Berland 王国由 $n$ 个城市和 $m$ 条双向道路组成,通过这些道路,可以从任意城市到达其他任何城市。国王 Vlad 的长子住在城市 $1$,次子住在城市 $n$。

为了控制所有往返于城市 $1$ 和城市 $n$ 之间的信使,Vlad 想要挑选一些城市并在其中建立秘密警察部门。事实证明,无论你多么强大,都无法做到完全保密。如果城市 $v$ 建立了警察部门,该市的市长会以某种方式知晓此事。此外,任何与 $v$ 直接相连的城市的市长也会知晓这些警察部门的存在。

当然,国王希望他的儿子们不要察觉到他的新秘密警察。因此,他有三个限制条件:

  1. 不应存在任何一条从城市 $1$ 到城市 $n$ 的路径,使得路径上经过的所有城市都没有警察部门。
  2. 城市 $1$ 和城市 $n$ 不能建立秘密警察部门。不过,与城市 $1$ 或城市 $n$ 直接相连的城市可以建立秘密警察部门。
  3. 知晓至少一个秘密警察部门存在的城市市长总数应尽可能少。

你不想帮助国王 Vlad 进行这些恶意游戏,但这个问题本身看起来很有趣,所以你想纯粹为了娱乐而找到最优解。

输入格式

输入的第一行包含一个整数 $t$ ($1 \le t \le 100$),表示测试用例的数量。

接下来是 $t$ 个测试用例的描述。每个测试用例的第一行包含两个整数 $n$ 和 $m$ ($3 \le n \le 300, 2 \le m \le \frac{n(n-1)}{2} - 1$),分别表示王国中的城市数量和道路数量。接下来的 $m$ 行,每行包含两个整数 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n, u_i \neq v_i$),表示第 $i$ 条双向道路连接的城市编号。

保证所有测试用例中 $n$ 的总和不超过 $300$。

对于每个测试用例,保证每条道路连接两个不同的城市,没有两条道路连接同一对城市,且没有道路直接连接城市 $1$ 和城市 $n$。

输出格式

对于每个测试用例,输出两行。第一行包含两个整数 $a$ 和 $k$,其中 $a$ 是答案,即知晓至少一个秘密警察部门存在的市长的最小可能数量,$k$ 是为了达到答案 $a$ 而需要建立的秘密警察部门的数量。下一行应包含 $k$ 个不同的索引 $x_1, x_2, \dots, x_k$ ($1 < x_i < n$),指明在最优解中这些秘密警察部门的具体位置。如果存在多个最优解,输出其中任意一个即可。

样例

输入 1

3
3 2
1 2
2 3
4 4
1 2
2 4
1 3
3 4
13 18
1 2
1 3
1 4
2 5
3 5
3 6
4 6
5 7
6 7
7 8
7 9
8 12
8 11
9 11
9 10
12 13
11 13
10 13

输出 1

3 1
2
4 2
2 3
5 1
7

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.