CF827B.High Load

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability.

Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes.

Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.

阿卡迪再次需要你的帮助!这次他决定构建自己的高速互联网交换点。该交换点应由 nn 个节点组成,这些节点通过尽可能少的网线连接成一个连通网络(每根网线直接连接两个节点)。其中恰好有 kk 个节点为出口节点(exit-nodes),即每个出口节点必须且仅与网络中的另一个节点相连;而其余所有节点则必须至少与两个节点相连,以提高系统稳定性。

阿卡迪希望系统尽可能快,因此他希望最小化任意两个出口节点之间的最大距离。两个节点之间的距离定义为数据包在二者之间传输所需经过的网线数量。

请帮助阿卡迪设计一种网络构建方案,使得距离最远的两个出口节点之间的距离尽可能小。

输入格式

The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes.

Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints.

第一行包含两个整数 nn 和 kk(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5,2≤k≤n−12 \leq k \leq n - 1)—— 分别表示节点总数和出口节点数。

注意:在给定约束条件下,总能构造出至少一个具有 nn 个节点和 kk 个出口节点的网络。

输出格式

In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to n. Exit-nodes can have any ids.

If there are multiple answers, print any of them.

第一行输出两个最远出口节点之间的最小可能距离。接下来的 n−1n-1 行中,每行输出两个整数:由导线连接的两个节点的编号。每条导线的描述恰好输出一次。导线及其端点的输出顺序可以任意。节点编号应为 11 到 nn。出口节点可以具有任意编号。

如果存在多个满足条件的答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3 2

    输出#1

    2
    1 2
    2 3
  • 输入#2

    5 3

    输出#2

    3
    1 2
    2 3
    3 4
    3 5

说明/提示

In the first example the only network is shown on the left picture.

In the second example one of optimal networks is shown on the right picture.

Exit-nodes are highlighted.

在第一个例子中,唯一的网络如左侧图片所示。

在第二个例子中,其中一个最优网络如右侧图片所示。

出口节点已高亮显示。

输入解题思路,AI测评打分。不知道怎么写?

首页