#P1260. 工程规划
工程规划
Description
Building a skyscraper is a challenging project composed of subtasks, numbered (). Due to strict constraints on the starting conditions of some tasks, the start times are not easy to determine (however, these start times are all non-negative integers because they must start after the entire project begins). For example: after excavation is completed, the foundation must be laid immediately; but after concrete pouring is completed, one must wait for a while before removing the formwork.
Such requirements can be expressed by () inequalities. An inequality of the form represents a constraint that the start times of tasks and must satisfy. The right-hand side of each inequality is a constant . These constants may differ, but they all lie within the interval .
Your task is to write a program that, given inequalities like the above, finds a possible sequence of start times , or determines that the problem has no solution. For solvable cases, the earliest task must start at the same time as the entire project, that is, at least one of equals .
Input Format
The first line contains two positive integers and separated by a space. Each of the next lines contains three integers separated by spaces, corresponding to the inequality .
Output Format
If there is a feasible solution, output lines. Each line contains a non-negative integer, and at least one of them must be , representing in order the start time of each task. If there is no feasible solution, output the message NO SOLUTION.
5 8
1 2 0
1 5 -1
2 5 1
3 1 5
4 1 4
4 3 -1
5 3 -1
5 4 -3
0
2
5
4
1
5 5
1 2 -3
1 5 -1
2 5 -1
5 1 -5
4 1 4
NO SOLUTION
Hint
SPJ provided by @zhouyonglong.
Translated by ChatGPT 5
京公网安备 11011102002149号