PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000027. Mẫu hệ bất đẳng thức hiệu (Difference Constraints Template)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Mẫu hệ bất đẳng thức hiệu (Difference Constraints Template)
Difference Constraints Template
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Given integer variables and constraints , output any integer assignment satisfying all constraints, or NO if no such assignment exists.
An output assignment is valid if it satisfies all constraints.
Input
First line: . Each of the next lines contains , expressing .
Output
Print NO if infeasible; otherwise print integer values .
Subtasks
- Subtask 1 (20 points): $2\le n\le 12; 1\le m\le 30; 1\le a,b\le n; a\ne b; -10^4\le c\le 10^4$.
- Subtask 2 (30 points): $2\le n\le 200; 1\le m\le 1200; 1\le a,b\le n; a\ne b; -10^4\le c\le 10^4$.
- Subtask 3 (50 points): $2\le n\le 5000; 1\le m\le 5000; 1\le a,b\le n; a\ne b; -10^4\le c\le 10^4$.
Examples
Input
3 3
1 2 3
2 3 -2
1 3 1
Output
0 -2 0
Explanation
The inequalities are , , and . The assignment satisfies them: respectively , , and . The answer file may contain another feasible assignment.