CF830E.Perpetual Motion Machine
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way.
Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes _x_2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers.
Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set.
It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106.
开发者彼得认为自己发明了一种永动机。具体来说,他拥有大量元件,每个元件的工作方式如下:
每个元件都有一个控制器,可将其设定为任意非负实数值。若某控制器被设定为值 x,则该控制器每秒消耗 x2 单位能量。同时,任意两个通过导线相连的元件每秒共同产生 y⋅z 单位能量,其中 y 和 z 分别是这两个元件控制器上设定的值。
彼得拥有的导线数量有限,因此他已经构建了某种由元件与导线组成的特定结构。现在他想知道:是否存在一种控制器设定方式,使得整个系统产生的能量至少等于其消耗的能量,并且至少有一个控制器的设定值不为 0?请你帮他判断这一点;若可行,请找出满足条件的一组整数设定值。
题目保证:若存在满足上述条件的控制器设定,则必存在一组满足条件的整数设定值,且所有值均不超过 106。
输入格式
There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.
There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires.
After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire.
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105.
For hacks you can only use tests with one test case.
输入包含若干个(至少一个)测试用例。第一行包含一个整数——测试用例的数量。
每个测试用例前有一空行。每个测试用例的第一行包含两个整数 n 和 m(1 ≤ n ≤ 105,0 ≤ m ≤ 105)——分别表示电路图中元件的数量和导线的数量。
接下来有 m 行,每行包含两个整数 a 和 b(1 ≤ a, b ≤ n)——表示由一根导线连接的两个元件。任意元件不会与自身相连,任意两个元件之间至多只有一根导线相连。
保证所有测试用例的 n 之和以及所有测试用例的 m 之和均不超过 105。
对于 Hack 测试,仅允许使用仅含一个测试用例的测试数据。
输出格式
Print answer for each test case.
For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them.
If it's not possible to set the controllers in the required way, print one line "NO".
对每个测试用例输出答案。
对每个测试用例,若存在一种控制器设置方式,使得消耗的功率不大于产生的功率,则输出一行 "YES",并在下一行输出所需的设置值。所有设置值必须为 0 到 106(含)之间的整数,且至少有一个值不为 0。若存在多种可行解,输出任意一种即可。
若不存在满足要求的控制器设置方式,则输出一行 "NO"。
输入输出样例
输入#1
4 4 4 1 2 2 3 3 4 4 2 3 2 2 3 3 1 4 6 1 2 3 4 4 2 1 4 1 3 3 2 10 9 2 1 3 2 5 2 6 2 2 7 2 8 2 9 2 10 4 2
输出#1
YES 1 2 2 1 NO YES 1 1 1 1 YES 1 5 1 1 1 1 1 1 1 1
说明/提示
In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES".
In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second.
在第一个例子中,可以按要求设置控制器,例如:将第一个元件的控制器设为 1,第二个和第三个元件的控制器均设为 2,第四个元件的控制器设为 1。此时,消耗功率为 12+22+22+12=10 能量单位/秒,产生功率为 1⋅2+2⋅2+2⋅1+2⋅1=10 能量单位/秒。因此答案为 “YES”。
在第二个测试用例中,无法按要求设置控制器。例如,若将所有控制器均设为 0.5,则消耗功率为 0.75 能量单位/秒,而产生功率仅为 0.5 能量单位/秒。
输入解题思路,AI测评打分。不知道怎么写?