PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000029. Trang trại của K nhỏ (Little K’s Farm)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trang trại của K nhỏ (Little K’s Farm)

Little K’s Farm

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn farms and three possible kinds of constraints: 1 a b c means value at aa is at least cc greater than at bb; 2 a b c means value at aa exceeds value at bb by at most cc; 3 a b requires equality. Determine consistency.

Input

First line n,mn,m, followed by mm constraints in one of the three formats.

Output

Print Yes if feasible, otherwise No.

Subtasks

  • Subtask 1 (20 points): $2\le n\le 12; 1\le m\le 30; 1\le a,b\le n; a\ne b; 1\le c\le5000$.
  • Subtask 2 (30 points): $2\le n\le 200; 1\le m\le1000; 1\le a,b\le n; a\ne b; 1\le c\le5000$.
  • Subtask 3 (50 points): $2\le n\le5000; 1\le m\le5000; 1\le a,b\le n; a\ne b; 1\le c\le5000$.

Examples

Input

3 3
1 1 2 2
2 1 3 4
3 2 3

Output

Yes

Explanation

Set x2=x3=0x_2=x_3=0 and x1=2x_1=2. Then x1−x2=2≥2x_1-x_2=2\ge2, x1−x3=2≤4x_1-x_3=2\le4, and x2=x3x_2=x_3, so Yes is correct.