def main():

    n, m = list(map(int, input().split()))

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

    for i in range(m):

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

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

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

    dis = [0] * n

    visited = [False] * n

    for i in range(n):

        if visited[i]:

            continue

        stack = list([i])

        visited[i] = True

        while len(stack):

            v = stack[-1]

            stack.pop()

            for u, d in g[v]:

                if not visited[u]:

                    dis[u] = dis[v] + d

                    stack.append(u)

                    visited[u] = True

    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, input().split()))

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

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

    for i in range(m):

        l, r, d = list(map(int, lines[i].split()))

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

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

    dis = [0] * n

    visited = [False] * n

    for i in range(n):

        if visited[i]:

            continue

        stack = list([i])

        visited[i] = True

        while len(stack):

            v = stack[-1]

            stack.pop()

            for u, d in g[v]:

                if not visited[u]:

                    dis[u] = dis[v] + d

                    stack.append(u)

                    visited[u] = True

    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()

def main():
    n, m = list(map(int, input().split()))
    g = [[] for i in range(n)]
    for i in range(m):
        l, r, d = list(map(int, input().split()))
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    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, input().split()))
    g = [[] for i in range(n)]
    lines = sys.stdin.read().splitlines()
    for i in range(m):
        l, r, d = list(map(int, lines[i].split()))
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    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 + + +    lines = sys.stdin.read().splitlines() -        l, r, d = list(map(int, input().split())) +        l, r, d = list(map(int, lines[i].split()))