D1. Construct an Array (Easy Version)
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This is the easy version of the problem. The difference between the versions is that in this version, $$$n \le 1000$$$ and $$$m=\frac{n(n+1)}{2}$$$.

You are given two integers $$$n$$$ and $$$m$$$. You need to construct an integer array $$$a$$$ of length $$$n$$$ that satisfies $$$m$$$ restrictions. Each restriction can be represented by a tuple $$$(o,i,j)$$$ such that $$$o \in \{1,2\}$$$ and $$$1 \le i \le j \le n$$$:

  • If $$$o=1$$$, the sum $$$a_i+a_j$$$ must be non-negative.
  • If $$$o=2$$$, the sum $$$a_i+a_j$$$ must be negative.
Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le \color{red}{1000}$$$, $$$m\color{red}{=}\frac{n(n+1)}{2}$$$), representing the length of the array $$$a$$$ you need to construct and the number of restrictions, respectively.

Each of the next $$$m$$$ lines contains three integers $$$o$$$, $$$i$$$, and $$$j$$$ ($$$o \in \{1,2\}$$$, $$$1 \le i \le j \le n$$$), representing a restriction. It is guaranteed that each pair of integers $$$i$$$ and $$$j$$$ such that $$$1 \le i \le j \le n$$$ occurs in at most one restriction.

It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$10^6$$$.

Output

For each test case, if no such array $$$a$$$ exists, output "NO".

Otherwise, first output "YES" on a single line. Then output $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$|a_i| \le 10^9$$$), representing the array $$$a$$$ you constructed. It can be proven that under the problem constraints, if such an array exists, there exists one where all elements in the array do not exceed $$$10^9$$$ in absolute value.

If there exist multiple arrays satisfying the requirement, you may output any of them.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example
Input
6
1 1
1 1 1
1 1
2 1 1
2 3
1 1 1
1 1 2
1 2 2
2 3
1 1 1
1 2 2
2 1 2
3 6
1 1 1
1 1 2
1 1 3
2 2 2
2 2 3
2 3 3
3 6
2 1 1
1 1 2
2 2 3
1 3 3
1 2 2
2 1 3
Output
YES
0
YES
-1
YES
0 0
NO
YES
1 -1 -1
NO
Note

In the first test case, the only restriction is that $$$a_1+a_1$$$ is non-negative, implying that $$$a_1$$$ is non-negative. Thus, $$$a_1$$$ can be any non-negative integer.

In the second test case, the only restriction is that $$$a_1+a_1$$$ is negative, implying that $$$a_1$$$ is negative. Thus, $$$a_1$$$ can be any negative integer.

In the fourth test case, the first and second restrictions imply that both $$$a_1$$$ and $$$a_2$$$ are non-negative. However, the third restriction forces $$$a_1+a_2$$$ to be negative, which leads to a contradiction.


Morty Proxy This is a proxified and sanitized view of the page, visit original site.