#P1850H. The Third Letter
The Third Letter
The Third Letter
题面翻译
组数据。对于每组数据:
第一行给定 和 ,表示有 个人和 个要求。每个人都站在数轴上的一个整数点上(可以在负半轴上)。
然后的 行,每行一个要求。每个要求包含 和 ,表示第 个人要站在第 个人前方的第 个位置(如果 是负数,则第 个人要站在第 个人后方的第 个位置)。问是否存在满足要求的方案。
$t \leq 100, \sum n \leq 2e5, m \leq n, -10^9 \leq d_i \leq 10^9$
题目描述
In order to win his toughest battle, Mircea came up with a great strategy for his army. He has soldiers and decided to arrange them in a certain way in camps. Each soldier has to belong to exactly one camp, and there is one camp at each integer point on the -axis (at points ).
The strategy consists of conditions. Condition tells that soldier should belong to a camp that is situated meters in front of the camp that person belongs to. (If , then 's camp should be meters behind 's camp.)
Now, Mircea wonders if there exists a partition of soldiers that respects the condition and he asks for your help! Answer "YES" if there is a partition of the soldiers that satisfies all of the conditions and "NO" otherwise.
Note that two different soldiers may be placed in the same camp.
输入格式
The first line contains a single integer ( ) — the number of test cases.
The first line of each test case contains two positive integers and ( ; ) — the number of soldiers, and the number of conditions respectively.
Then lines follow, each of them containing integers: , , ( ; ; ) — denoting the conditions explained in the statement. Note that if is positive, should be meters in front of and if it is negative, should be meters behind .
Note that the sum of over all test cases doesn't exceed .
输出格式
For each test case, output "YES" if there is an arrangement of the soldiers that satisfies all of the conditions and "NO" otherwise.
样例 #1
样例输入 #1
4
5 3
1 2 2
2 3 4
4 2 -6
6 5
1 2 2
2 3 4
4 2 -6
5 4 4
3 5 100
2 2
1 2 5
1 2 4
4 1
1 2 3
样例输出 #1
YES
NO
NO
YES
提示
For the first test case, we can partition the soldiers into camps in the following way: soldier:
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
For the second test case, there is no partition that can satisfy all the constraints at the same time.
For the third test case, there is no partition that satisfies all the constraints since we get contradictory information about the same pair.
For the fourth test case, in order to satisfy the only condition, a possible partition is:
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
- Soldier in the camp with the coordinate .
相关
在以下作业中: