#P1993. 小 K 的农场

    ID: 938 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论广度优先搜索,BFS差分约束

小 K 的农场

Description

Xiao K has built many farms in MC (Minecraft), a total of nn, to the point that he has forgotten the exact amount of crops planted in each farm. He only remembers some vague information (a total of mm pieces), described in the following three forms:

  • Farm aa has planted at least cc more units of crops than farm bb.
  • Farm aa has planted at most cc more units of crops than farm bb.
  • Farm aa and farm bb have planted the same number of crops.

However, because Xiao K’s memory may be inaccurate, he wants to know whether there exists a configuration such that the number of crops in the farms is consistent with all the pieces of information he remembers.

Input Format

The first line contains two integers nn and mm, representing the number of farms and the number of pieces of information remembered by Xiao K.

The next mm lines:

  • If the first number of a line is 11, then three integers a,b,ca, b, c follow, meaning farm aa has planted at least cc more units of crops than farm bb.
  • If the first number of a line is 22, then three integers a,b,ca, b, c follow, meaning farm aa has planted at most cc more units of crops than farm bb.
  • If the first number of a line is 33, then two integers a,ba, b follow, meaning farm aa has planted the same number of crops as farm bb.

Output Format

If there exists a configuration consistent with Xiao K’s memory, output Yes, otherwise output No.

3 3
3 1 2
1 1 3 1
2 2 3 2

Yes

Hint

For 100%100\% of the testdata, it is guaranteed that 1n,m,a,b,c5×1031 \le n, m, a, b, c \le 5 \times 10^3.

Translated by ChatGPT 5