Funny Graph

Time limit: 0.5s Memory limit: 64MB Input: Output:

Bugland is a country with NN cities. Being a newly founded country, the NN cities are not connected by any roads, thus the government decided to initiate a project which will last exactly MM days and whose purpose is to create a network of roads between the cities.

In each day of the project, the workers build two new weighted unidirectional roads, one from city xx to city yy whose weight is zz and one from city yy to city xx whose weight is z-z.

After each day the inhabitants of Bugland ask themselves a question: is there a way of to label the cities with numbers such that if there is an edge from city xx to city yy, the weight of the edge is CxCyC_x-C_y, where CiC_i is the label of the ithi^{th} city?

Input data

The first line will contain the number of cities NN and the number of days of the project MM. The next MM lines each contain three numbers x,y,zx, y, z describing the roads built in each day.

Output data

You will write MM lines, on the ithi^{th} line YEP :) if there is a way to number the cities, or NOPE :/ if there is none.

Constraints and clarifications

  • 1N51041 \leq N \leq 5 \cdot 10^4
  • 1M1051 \leq M \leq 10^5
  • 109zi109  1iM-10^9 \leq z_i \leq 10^9\ \forall\ 1 \leq i \leq M
  • 0xi,yiN1  1iM0 \leq x_i, y_i \leq N - 1\ \forall\ 1 \leq i \leq M
  • For tests worth 3030 points: 1N1031 \leq N \leq 10^3 and 1M1041 \leq M \leq 10^4
  • Bugland can have multiple roads between two cities or roads form one city to itself.

Example 1

stdin

4 5 
0 1 1 
1 3 -1 
3 0 0 
3 2 4 
2 0 3

stdout

YEP :)
YEP :)
YEP :)
YEP :)
NOPE :/

Log in or sign up to be able to send submissions!