构造数组(简单版)AI (CI翻译)
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}$.
$n \le 1000$ 且 $m=\frac{n(n+1)}{2}$。**AI (CI翻译)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$:
给定两个整数 $n$ 和 $m$。你需要构造一个长度为 $n$ 的整数数组 $a$,使其满足 $m$ 条限制。每条限制可以表示为一个三元组 $(o,i,j)$,其中 $o \in \{1,2\}$ 且 $1 \le i \le j \le n$:AI (CI翻译)
- 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.
- 如果
$o=1$,则$a_i+a_j$必须非负。 - 如果
$o=2$,则$a_i+a_j$必须为负数。
Input
输入格式
AI (CI翻译)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.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
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.
每个测试用例的第一行包含两个整数 $n$ 和 $m$($1 \le n \le \color{red}{1000}$,$m\color{red}{=}\frac{n(n+1)}{2}$),分别表示需要构造的数组 $a$ 的长度以及限制的数量。AI (CI翻译)
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.
接下来的 $m$ 行中,每行包含三个整数 $o$、$i$ 和 $j$($o \in \{1,2\}$,$1 \le i \le j \le n$),表示一条限制。保证每一对满足 $1 \le i \le j \le n$ 的整数 $i$ 和 $j$ 至多出现在一条限制中。AI (CI翻译)
It is guaranteed that the sum of $m$ over all test cases does not exceed $10^6$.
保证所有测试用例的 $m$ 之和不超过 $10^6$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, if no such array $a$ exists, output "NO".
对于每个测试用例,如果不存在满足条件的数组 $a$,输出“NO”。AI (CI翻译)
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.
否则,首先在单独一行输出“YES”。然后输出 $n$ 个整数 $a_1,a_2,\ldots,a_n$($|a_i| \le 10^9$),表示构造出的数组 $a$。可以证明,在题目的限制下,如果存在满足条件的数组,则一定存在一个所有元素绝对值均不超过 $10^9$ 的数组。AI (CI翻译)
If there exist multiple arrays satisfying the requirement, you may output any of them.
如果存在多个满足条件的数组,可以输出其中任意一个。AI (CI翻译)
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.
你可以使用任意大小写形式输出答案(大写或小写均可)。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)
Note
说明
AI (CI翻译)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.
在第一个测试用例中,唯一的限制是 $a_1+a_1$ 非负,这意味着 $a_1$ 非负。因此,$a_1$ 可以是任意非负整数。AI (CI翻译)
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.
在第二个测试用例中,唯一的限制是 $a_1+a_1$ 为负,这意味着 $a_1$ 为负。因此,$a_1$ 可以是任意负整数。AI (CI翻译)
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.
在第四个测试用例中,第一条和第二条限制意味着 $a_1$ 和 $a_2$ 都是非负数。然而,第三条限制强制要求 $a_1+a_2$ 为负数,从而产生矛盾。
AI (CI翻译)
样例
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
YES
0
YES
-1
YES
0 0
NO
YES
1 -1 -1
NO
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。