Submit solution

Points: 100
Time limit: 3.0s
Python 3 10.0s
Memory limit: 940M

Author:
Problem type

Indra is excited, because they have just learned Haskell! Now that they have acquired the skills of a functional programming god, they want to start working on a project. The project can be modeled as a graph of n tasks, connected by m directed edges. First, Indra starts on any task of their choice. Then, they repeatedly move from their current task to a connected non-completed task, completing it. Indra will continue this process until eventually landing back at their original task, creating a cycle.

When Indra completes a task, their productivity goes up by the weight of the edge connecting their current task and the to-be-completed task. However, Haskell can be frustrating - if this process would involve fighting compiler errors, their productivity could go down instead of up, represented by a negative edge weight.

Josh has claimed that there are no projects that are easier to complete in Haskell than in other languages. More formally, he claims that there is no cycle in the graph such that the edge weights sum to a (strictly) positive number. It is your job to help Indra with their task - given a graph, is there a cycle with positive edge weight?

Input Format

The first line of input will consist of two integers, n and m. The next m lines will each consist of three integers a and b and c, meaning that there is a directed edge from node a to b with weight c.

Output Format

The output should consist of either "YES" or "NO", depending on whether there exists a positive weight cycle.

Input Constraints

n \le 1e2

m \le 1e2

1 \le a,b \le n

-100 \le c \le 100

Sample Input 1

3 6
3 1 -80
1 3 -58
1 3 81
2 3 -81
2 1 24
2 1 -55

Sample Output 1

YES

Sample Explanation

There is at least positive one graph in the cycle, 1->3->1 (with weight -80+81 = 1).


Comments

There are no comments at the moment.