CF2196F.Indivisible
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two numbers n and m.
An undirected graph is called beautiful if it satisfies the following conditions:
- It has no loops or multiple edges.
- It has exactly n vertices and m edges.
- Its vertices cannot be divided into 2 sets such that the sums of the degrees of all vertices in the first set and the sums of the degrees of all vertices in the second set are equal.
You need to either report that a beautiful undirected graph with the given n,m does not exist, or provide one.
给你两个数 n 和 m。
一个无向图被称为优美图,当且仅当它满足以下条件:
- 它不含自环或重边。
- 它恰好有 n 个顶点和 m 条边。
- 它的顶点无法被划分为两个集合,使得第一个集合中所有顶点的度数之和等于第二个集合中所有顶点的度数之和。
你需要判断:是否存在满足给定 n,m 的优美无向图。若不存在,请报告;否则,请构造出一个这样的图。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains two integers n,m (12≤n≤105,1≤m≤min(2⋅105,2n(n−1))) — the number of vertices and edges in the graph.
It is guaranteed that the sum of n across all test cases does not exceed 105, and the sum of m across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅一行,包含两个整数 n,m(12≤n≤105, 1≤m≤min(2⋅105,2n(n−1))),分别表示图中的顶点数和边数。
保证所有测试用例中 n 的总和不超过 105,且所有测试用例中 m 的总和不超过 2⋅105。
输出格式
For each test case, output "No" if such a graph does not exist. Otherwise, output "Yes", and then, in the following m lines — the edges of the beautiful graph in arbitrary order. If there are multiple answers, you may output any of them.
对于每个测试用例,若这样的图不存在,则输出“No”。否则,输出“Yes”,然后在接下来的 m 行中以任意顺序输出该优美图的各条边。若存在多个可行答案,输出任意一个即可。
输入输出样例
输入#1
5 12 7 12 1 90000 12 30 434 30 435
输出#1
Yes 1 2 2 3 3 4 4 5 5 1 1 3 2 4 No Yes 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 5 6 No No
说明/提示
In the first test case, the graph is a simple cycle of 7 vertices. The degrees of the vertices are 2,2,2,2,2,2,2,0,0,0,0,0. It is easy to see that in such a graph, it is impossible to divide the vertices into 2 parts with equal sums of degrees.
In the second test case, since m=1, it is easy to see that the vertices can always be divided into 2 parts with equal sums of degrees. Therefore, no solution exists.
在第一个测试用例中,该图是一个包含 7 个顶点的简单环。各顶点的度数为 2,2,2,2,2,2,2,0,0,0,0,0。显然,在这样的图中,无法将顶点划分为 2 部分,使得两部分的度数之和相等。
在第二个测试用例中,由于 m=1,显然顶点总能被划分为 2 部分,使得两部分的度数之和相等。因此,不存在满足条件的解。
输入解题思路,AI测评打分。不知道怎么写?