Ensure that you are logged in and have the required permissions to access the test.

Monk's Business Day

3.9

29 votes
Problem

Monk visits Biksy, the largest trading market in the land. Biksy has traders from all over the world.
There are a total of N items indexed from 1 to N, that are traded in the market by a total of M dealers. Each trader is characterized by three integers, say i, j, C , meaning that the trader will take i'th item from you and give you j'th item and C units of money. A negative value of C signifies that, in order to get j'th item from the trader, you will have to give i'th item and C units of money. Note that there can be multiple dealers who deal with the same pair of items and some crazy dealers might trade the same item as well i.e. (i = j).
Monk visits Biksy having the item number 1. He collects the data of all the traders and wants to know if there is way by which he can become infinity rich if he acts smart! i.e. if there are a series of profits, repeating which, will always increase the number of units of money with him! Help Monk find the answer to this question. Note that Monk can go to any dealer any number of times.

Input:
First line contains an integer T. T test cases follow.
First line of each test case contains two space-separated integers N, M
Next M lines contain three space-separated integers i, j and C, the characteristics of the traders.

Output:
Print "Yes"(without the quotes) if such a way exists, "No"(without the quotes) otherwise.
Print the answer to each test case in a new line.

Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 100
1 ≤ M ≤ 1000
1 ≤ i, jN
-1000 ≤ C ≤ 1000

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For the first test case, there is no such way possible.
For the second test case, Monk starts with item 1.
Trades it for 5th item gaining 10 units.
Trades 5th for 2nd gaining 5 units.
Trades 2nd for 4th losing 10 units.
Trades 4th for 1st gaining 1 unit.
Thereby, gaining 6 units in this process and it can be repeated indefinitely to make Monk infinitely rich!

Editor Image

?