CSES - Aalto Competitive Programming 2024 - wk6 - Wed - Online feud
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Uolevi has stumbled upon an ancient online feud. The feud is probably about that one TV show that has multiple endings since people are talking about little and big ends. There would seem to be a clear divide between little-endians and big-endians but Uolevi wishes to double check this fact by analyzing the like & dislike statistics.

There are nn users numbered 1,2,,n1,2,\dots,n on the site and mm dislikes/likes. The ii-th dislike/like was from user aia_i about user bib_i's comment and was of type cic_i. If it was a like, then ci=1c_i = 1, otherwise ci=1c_i = -1. Uolevi wants to check whether the users can be split into two groups where the members of one group have only liked or received likes from their own group and only disliked or received dislikes from the opposite group. One of the groups may be empty.

Input

The first line contains two integers nn and mm. The ii-th of next mm following line contains three integers ai,bi,a_i,\,b_i, and cic_i.

Output

Print "Yes" if there is a clear division and "No" otherwise.

Constraints

  • 2n1052 \le n \le 10^5
  • 1m2×1051 \le m \le 2 \times 10^5
  • 1ai,bin1 \le a_i, b_i \le n
  • aibia_i \neq b_i
  • ci=1c_i = 1 or ci=1c_i = -1

Example 1

Input:

5 7
4 5 1
1 3 1
1 4 -1
1 4 -1
4 5 1
2 4 -1
4 3 -1

Output:

Yes

Example 2

Input:

5 6
4 5 1
1 2 -1
1 2 1
2 1 1
2 4 1
5 3 -1

Output:

No