You are given a directed graph consisting of vertices and edges (each edge is directed, so it can be traversed in only one direction). You need to assign a value to each vertex from 1 to so that for each edge having weight , is satisfied.
The first line contains two integers and () — the number of vertices and the number of edges, respectively.
Then lines follow. Each line contains three integers and and denoting a directed edge going from vertex to vertex with weight (). Each ordered pair is listed at most once (there is at most one directed edge from to ).
If there exists any solution print "YES"(without quotes) on the first line. Then on the next line output integers where integer is the value of () i.e. the value assigned to each vertex for each from 1 to . If there are multiple ways to assign values, output any.
If there is no way to assign values to each vertex such that the above conditions are satisfied just print "NO"(without quotes) ending with a new line.
Note that on any line you can't print any trailing space.
Input | Output |
---|---|
4 3 1 2 10 2 3 5 4 2 1 | YES 0 0 0 0 |