import sys





def main():

    n, m = list(map(int, sys.stdin.readline().split()))

    g = [[] for i in range(n)]

    deg = [0] * n

    lines = sys.stdin.read().splitlines()

    for line in lines:

        l, r, d = list(map(int, line.split()))

        g[l - 1].append((r - 1, d))

        deg[r - 1] += 1

    dis = [-1] * n

    for i in range(n):

        if deg[i]:

            continue

        stack = list([i])

        dis[i] = 0

        while len(stack):

            v = stack[-1]

            stack.pop()

            for u, d in g[v]:

                if dis[u] == -1:

                    dis[u] = dis[v] + d

                    stack.append(u)

    for v in range(n):

        for u, d in g[v]:

            if dis[v] + d != dis[u]:

                print('No')

                return

    print('Yes')





if __name__ == '__main__':

    main()

import sys





def main():

    n, m = list(map(int, sys.stdin.readline().split()))

    g = [[] for i in range(n)]

    deg = [0] * n

    for i in range(m):

        l, r, d = list(map(int, sys.stdin.readline().split()))

        g[l - 1].append((r - 1, d))

        deg[r - 1] += 1

    dis = [-1] * n

    for i in range(n):

        if deg[i]:

            continue

        stack = list([i])

        dis[i] = 0

        while len(stack):

            v = stack[-1]

            stack.pop()

            for u, d in g[v]:

                if dis[u] == -1:

                    dis[u] = dis[v] + d

                    stack.append(u)

    for v in range(n):

        for u, d in g[v]:

            if dis[v] + d != dis[u]:

                print('No')

                return

    print('Yes')





if __name__ == '__main__':

    main()

import sys


def main():
    n, m = list(map(int, sys.stdin.readline().split()))
    g = [[] for i in range(n)]
    deg = [0] * n
    lines = sys.stdin.read().splitlines()
    for line in lines:
        l, r, d = list(map(int, line.split()))
        g[l - 1].append((r - 1, d))
        deg[r - 1] += 1
    dis = [-1] * n
    for i in range(n):
        if deg[i]:
            continue
        stack = list([i])
        dis[i] = 0
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if dis[u] == -1:
                    dis[u] = dis[v] + d
                    stack.append(u)
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print("No")
                return
    print("Yes")


if __name__ == "__main__":
    main()

import sys


def main():
    n, m = list(map(int, sys.stdin.readline().split()))
    g = [[] for i in range(n)]
    deg = [0] * n
    for i in range(m):
        l, r, d = list(map(int, sys.stdin.readline().split()))
        g[l - 1].append((r - 1, d))
        deg[r - 1] += 1
    dis = [-1] * n
    for i in range(n):
        if deg[i]:
            continue
        stack = list([i])
        dis[i] = 0
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if dis[u] == -1:
                    dis[u] = dis[v] + d
                    stack.append(u)
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print("No")
                return
    print("Yes")


if __name__ == "__main__":
    main()

-    lines = sys.stdin.read().splitlines() -    for line in lines: -        l, r, d = list(map(int, line.split())) +    for i in range(m): +        l, r, d = list(map(int, sys.stdin.readline().split()))