QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#2619. 直径二

统计

你正在为一家新公司构建计算机网络。该网络由 $n$ 个节点组成,编号从 $1$ 到 $n$。节点可以通过双向线路连接。每条线路连接恰好两个节点。每对节点之间最多只能有一条线路。如果一条线路连接了两个节点,我们称这两个节点为直接相连。

前 $k$ 个节点(编号为 $1, 2, \dots, k$)为不可信节点,必须安全地连接到网络中。这些节点中的每一个都必须恰好与另一个节点直接相连。

其余 $n - k$ 个节点(编号为 $k + 1, k + 2, \dots, n$)为可信节点,必须可靠地连接到网络中。这些节点中的每一个都必须至少与另外两个节点直接相连。

网络的直径不得超过 $2$:对于任意两个节点 $i$ 和 $j$,它们要么直接相连,要么存在一个节点 $k$,使得节点 $i$ 和 $k$ 直接相连,且节点 $k$ 和 $j$ 直接相连。

为了最小化成本,所使用的线路数量必须尽可能少。

请构建一个满足上述所有条件的网络,如果无法实现,请报告。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 50$)。接下来是各测试用例的描述。

每个测试用例仅包含一行,包含两个整数 $n$ 和 $k$,分别表示节点总数和不可信节点的数量 ($3 \le n \le 50; 0 \le k \le n$)。

输出格式

对于每个测试用例,如果无法构建满足给定条件的网络,请输出一个整数 $-1$。

否则,在第一行输出所使用的线路数量 $m$。在接下来的 $m$ 行中,每行输出两个整数 $u_i$ 和 $v_i$,表示第 $i$ 条线路连接的节点编号 ($1 \le u_i, v_i \le n; u_i \neq v_i$)。

样例

样例输入 1

3
3 0
5 2
6 6

样例输出 1

3
1 2
1 3
2 3
5
1 3
2 3
3 4
3 5
4 5
-1

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.