#P5960. 【模板】差分约束
【模板】差分约束
Problem Description
You are given a system of inequalities with inequalities and unknowns of the form:
$$\begin{cases} x_{c_1}-x_{c'_1}\leq y_1 \\x_{c_2}-x_{c'_2} \leq y_2 \\ \cdots\\ x_{c_m} - x_{c'_m}\leq y_m\end{cases}$$Find any set of values that satisfies this system of inequalities.
Input Format
The first line contains two positive integers , representing the number of unknowns and the number of inequalities.
The next lines each contain three integers , representing an inequality .
Output Format
Output one line with numbers, representing a feasible solution . If there are multiple solutions, output any one of them. If there is no solution, output NO.
3 3
1 2 3
2 3 -2
1 3 1
5 3 5
Hint
Sample Explanation
$\begin{cases}x_1-x_2\leq 3 \\ x_2 - x_3 \leq -2 \\ x_1 - x_3 \leq 1 \end{cases}$
One feasible solution is .
$\begin{cases}5-3 = 2\leq 3 \\ 3 - 5 = -2 \leq -2 \\ 5 - 5 = 0\leq 1 \end{cases}$
Constraints
For of the testdata, , , , and .
Scoring Policy
You will get points as long as your output satisfies the system of inequalities. Please make sure the numbers in your output are within the int range.
If there is no solution but your program outputs a solution, the SPJ will return There is no answer, but you gave it, and the result will be WA.
If there is no solution and your program outputs NO, the SPJ will return No answer, and the result will be AC.
If a solution exists but your output is incorrect, the SPJ will return Wrong answer, and the result will be WA.
If a solution exists and your output is correct, the SPJ will return The answer is correct, and the result will be AC.
Translated by ChatGPT 5