import sys

input = sys.stdin.readline



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



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

edge = [{} for _ in range(n)]



for i in range(m):

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

    l, r  = l-1, r-1

    g[r].append(l)

    g[l].append(r)

    edge[l][r] = d

    edge[r][l] = -d



s = []

visit = [10**18]*n

for i in range(n):

    if visit[i] != 10**18:

        continue

    s.append(i)

    visit[i] = 0

    while s:

        v = s.pop()

        for u in g[v]:

            if visit[u] != 10**18:

                if visit[u] != visit[v]+edge[v][u]:

                    print('No')

                    exit()

            else:

                visit[u] = visit[v]+edge[v][u]

                s.append(u)

else:

    print('Yes')
import sys

#input = sys.stdin.readline

input = sys.stdin.buffer.readline



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

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

for i in range(m):

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

    l, r = l-1, r-1

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

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



s = []

visit = [-1]*n

dist = [False]*n

for i in range(n):

    if visit[i] == -1:

        s.append(i)

        visit[i] = 0

        dist[i] = 0

        while s:

            v = s.pop()

            for d, u in g[v]:

                if dist[u]:

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

                        print('No')

                        exit()

                if visit[u] == -1:

                    visit[u] = 0

                    dist[u] = dist[v]+d

                    s.append(u)

else:

    print('Yes')

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
edge = [{} for _ in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    l, r = l - 1, r - 1
    g[r].append(l)
    g[l].append(r)
    edge[l][r] = d
    edge[r][l] = -d
s = []
visit = [10**18] * n
for i in range(n):
    if visit[i] != 10**18:
        continue
    s.append(i)
    visit[i] = 0
    while s:
        v = s.pop()
        for u in g[v]:
            if visit[u] != 10**18:
                if visit[u] != visit[v] + edge[v][u]:
                    print("No")
                    exit()
            else:
                visit[u] = visit[v] + edge[v][u]
                s.append(u)
else:
    print("Yes")

import sys

# input = sys.stdin.readline
input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    l, r = l - 1, r - 1
    g[l].append((d, r))
    g[r].append((-d, l))
s = []
visit = [-1] * n
dist = [False] * n
for i in range(n):
    if visit[i] == -1:
        s.append(i)
        visit[i] = 0
        dist[i] = 0
        while s:
            v = s.pop()
            for d, u in g[v]:
                if dist[u]:
                    if dist[u] != dist[v] + d:
                        print("No")
                        exit()
                if visit[u] == -1:
                    visit[u] = 0
                    dist[u] = dist[v] + d
                    s.append(u)
else:
    print("Yes")

-input = sys.stdin.readline +# input = sys.stdin.readline +input = sys.stdin.buffer.readline -edge = [{} for _ in range(n)] -    g[r].append(l) -    g[l].append(r) -    edge[l][r] = d -    edge[r][l] = -d +    g[l].append((d, r)) +    g[r].append((-d, l)) -visit = [10**18] * n +visit = [-1] * n +dist = [False] * n -    if visit[i] != 10**18: -        continue -    s.append(i) -    visit[i] = 0 -    while s: -        v = s.pop() -        for u in g[v]: -            if visit[u] != 10**18: -                if visit[u] != visit[v] + edge[v][u]: -                    print("No") -                    exit() -            else: -                visit[u] = visit[v] + edge[v][u] -                s.append(u) +    if visit[i] == -1: +        s.append(i) +        visit[i] = 0 +        dist[i] = 0 +        while s: +            v = s.pop() +            for d, u in g[v]: +                if dist[u]: +                    if dist[u] != dist[v] + d: +                        print("No") +                        exit() +                if visit[u] == -1: +                    visit[u] = 0 +                    dist[u] = dist[v] + d +                    s.append(u)