CF2172N.New Kingdom

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In the upcoming strategy game Island Cartographer: Penultimate Chapter (ICPC), players take the role of bridge engineers employed by the Imperial Cartography & Planning Council to design a new kingdom spread across an archipelago of nn islands connected by a network of causeways. To achieve balance between stability and exploration, the council requires that the player's plan satisfy several strict rules.

The first and fundamental requirement is that the kingdom must be simple and connected. That is, each causeway connects two different islands, no two causeways connect the same pair of islands, and for each pair of different islands, there exists a route between them using a sequence of causeways.

After learning the ancient wisdom of the legendary tourist Euler, some visitors might be able to traverse every causeway exactly once in a single, seamless tour. If this is possible, then those visitors would not have enough time to enjoy their trips. To make them travel for longer, the council's second requirement is that exactly kk islands have an odd number of causeways connected to them.

Some causeways are considered vital to the kingdom. A causeway is vital if removing it would make travel between some pair of islands impossible. These causeways are important for local development, cultural identity, and tourism, but having too many of them could lead to traffic congestion. Therefore, the council's third and final requirement is that the kingdom must contain exactly bb vital causeways.

To complete a game of ICPC, the player must submit a plan to build causeways that satisfies all the requirements for the parameters nn, kk, and bb provided by the council. Before the game's release, you are tasked with testing the game by designing a valid kingdom plan as the player. In case the game is impossible to complete, please report so.

在即将推出的策略游戏《岛屿测绘师:倒数第二章》(ICPC)中,玩家将扮演帝国测绘与规划委员会(Imperial Cartography & Planning Council)雇佣的桥梁工程师,负责为一片由 nn 座岛屿组成的群岛设计一个新王国,这些岛屿通过一系列堤道(causeways)相互连接。为在稳定性与探索性之间取得平衡,委员会要求玩家的设计方案必须满足若干严格规则。

第一条、也是最基本的要求是:该王国必须是简单且连通的。即:每条堤道连接两座不同的岛屿;任意两座岛屿之间至多只有一条堤道相连;且对任意两个不同的岛屿,均存在一条仅由堤道构成的路径将它们连通。

受传奇旅行家欧拉(Euler)古老智慧的启发,部分游客或许能够恰好遍历每条堤道一次,完成一次无缝衔接的环游。若这种情况可行,则游客将没有足够时间充分欣赏沿途风光。为延长其旅行时长,委员会提出的第二条要求是:恰好有 kk 座岛屿拥有奇数条堤道与之相连。

某些堤道被视为王国的关键堤道(vital causeways)。若移除某条堤道会导致某对岛屿之间无法通行,则该堤道即为关键堤道。这些堤道对本地发展、文化认同及旅游业至关重要;但若数量过多,则可能导致交通拥堵。因此,委员会提出的第三条、也是最后一条要求是:该王国必须恰好包含 bb 条关键堤道。

要完成一场 ICPC 游戏,玩家必须提交一份堤道建造方案,使其同时满足委员会给定的参数 nn、kk 和 bb 所对应的所有要求。在游戏发布前,你被委派以玩家身份设计一个合法的王国方案来测试游戏。若针对给定参数不存在可行方案,请予以报告。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt. The description of the test cases follows.

The only line of each test case contains three integers nn, kk, and bb, representing the number of islands, the exact number of islands connected to an odd number of causeways, and the exact number of vital causeways, respectively.

  • 1≤n≤1051\le n\le 10^5
  • 0≤k≤n0\le k \le n
  • 0≤b≤n−10\le b \le n-1
  • The sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt。随后是各测试用例的描述。

每个测试用例仅有一行,包含三个整数 nn、kk 和 bb,分别表示岛屿的数量、恰好与奇数座堤道相连的岛屿数量,以及关键堤道的数量。

  • 1≤n≤1051\le n\le 10^5
  • 0≤k≤n0\le k \le n
  • 0≤b≤n−10\le b \le n-1
  • 所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, if there are no solutions that fit the requirements for a valid plan, output "No" in a single line.

Otherwise, output "Yes" in the first line. Then, output a single integer mm in the second line, indicating the number of causeways in your plan. In each of the next mm lines, output two integers uiu_i and viv_i separated by a whitespace, meaning that the islands uiu_i and viv_i are connected with a single causeway. If there are multiple valid plans, output any.

Your output must satisfy:

  • 0≤m≤5n0\le m\le 5n
  • For all 1≤i≤m1\le i\le m, 1≤ui,vi≤n1\le u_i, v_i\le n.
  • For all 1≤i≤m1\le i\le m, ui≠viu_i\neq v_i.
  • For all i≠ji\neq j, ui,vi≠uj,vj{u_i, v_i}\neq {u_j, v_j}.

It can be proven that for every possible input that has a solution, there exists a solution that satisfies these constraints.

对于每个测试用例,若不存在满足有效规划要求的解,则在一行中输出“No”。

否则,在第一行输出“Yes”。然后在第二行输出一个整数 mm,表示你所规划的堤道数量。接下来的 mm 行中,每行输出两个由空格分隔的整数 uiu_i 和 viv_i,表示岛屿 uiu_i 与 viv_i 之间修建一条堤道。若存在多个有效规划,输出任意一个即可。

你的输出必须满足以下条件:

  • 0≤m≤5n0\le m\le 5n
  • 对所有 1≤i≤m1\le i\le m,有 1≤ui,vi≤n1\le u_i, v_i\le n。
  • 对所有 1≤i≤m1\le i\le m,有 ui≠viu_i\neq v_i。
  • 对所有 i≠ji\neq j,有 {ui,vi}≠{uj,vj}\{u_i, v_i\}\neq \{u_j, v_j\}。

可以证明:对每个存在解的输入,均存在一个满足上述约束的解。

输入输出样例

  • 输入#1

    4
    6 2 1
    3 1 2
    4 0 0
    5 4 2

    输出#1

    Yes
    7
    1 2
    1 3
    2 3
    3 4
    4 5
    4 6
    5 6
    No
    Yes
    4
    1 2
    2 3
    3 4
    4 1
    Yes
    5
    1 4
    1 2
    4 5
    5 1
    5 3

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

首页