#graph301. 差分约束系统
差分约束系统
Difference Constraints System
Problem Description
Given a system of inequalities with unknowns of the form:
$$\begin{cases} x_{c_1} - x_{c'_1} \le y_1 \\ x_{c_2} - x_{c'_2} \le y_2 \\ \cdots \\ x_{c_m} - x_{c'_m} \le y_m \end{cases}$$Find a non-negative solution satisfying this system of inequalities, with each variable as small as possible.
Input Format
The first line contains two positive integers , the number of unknowns and the number of inequalities.
The next lines each contain three integers , representing an inequality .
It is guaranteed that $1 \le n, m \le 5 \times 10^3,\ -10^4 \le y \le 10^4,\ 1 \le c, c' \le n,\ c \ne c'$.
Output Format
One line with numbers: . If there is no solution, output -1.
Sample Input
3 3
1 2 3
2 3 -2
1 3 1
Sample Output
0 0 2