#P11640. Graph
Graph
Background
Hack testdata has been added in Subtask #5 and is not scored.
Problem Description
There is a graph with vertices. Each vertex can be black or white.
There are constraints. The -th constraint gives , meaning that from to there must exist a path of length . The path may pass through an edge or a vertex multiple times.
Determine whether there exists a directed graph whose edges all have weight , such that:
- All the above constraints are satisfied.
- If the graph has edges, then for every , let the -th edge be directed from to . Then the colors of and are different.
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains two integers .
The next lines each contain three integers .
Output Format
Output lines. Each line contains a string .
The -th line is the answer to the -th test case.
1
5 4
1 3 4
4 2 7
4 4 0
5 2 1
Yes
Hint
[Sample Explanation]
You can construct

to satisfy the requirements.
[Constraints]
This problem uses bundled tests.
- Subtask #1 (): .
- Subtask #2 (): .
- Subtask #3 (): .
- Subtask #4 (): no special constraints.
For of the data, , , , , .
Translated by ChatGPT 5