from collections import deque

N,M = list(map(int,input().split()))



Tree = [[] for _ in range(N)]

for _ in range(M):

    L,R,D = list(map(int,input().split()))

    L -= 1; R -= 1

    Tree[L].append((R,D))

    Tree[R].append((L,-D))



num = dict()

for i in range(N):

    if i not in num:

        num[i] = 0

        Q = deque(Tree[i])

        x = 0

        while Q:

            now,d = Q.popleft()

            if now in num:

                if num[now] != d:

                    print("No")

                    exit()

            else:

                num[now] = d

                for node,Di in Tree[now]:

                    Q.append((node,d+Di))

print("Yes")
from collections import deque

import sys

input = sys.stdin.readline  #文字列入力では注意！



N,M = list(map(int,input().split()))

Graph = [[] for _ in range(N)]

for _ in range(M):

    L,R,D = list(map(int,input().split()))

    L -= 1; R -= 1

    Graph[L].append((R,D))

    Graph[R].append((L,-D))



num = dict()

for i in range(N):

    if i not in num:

        num[i] = 0

        Q = deque(Graph[i])

        x = 0

        while Q:

            now,d = Q.popleft()

            if now in num:

                if num[now] != d:

                    print("No")

                    exit()

            else:

                num[now] = d

                for node,Di in Graph[now]:

                    Q.append((node,d+Di))

print("Yes")

from collections import deque

N, M = list(map(int, input().split()))
Tree = [[] for _ in range(N)]
for _ in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    Tree[L].append((R, D))
    Tree[R].append((L, -D))
num = dict()
for i in range(N):
    if i not in num:
        num[i] = 0
        Q = deque(Tree[i])
        x = 0
        while Q:
            now, d = Q.popleft()
            if now in num:
                if num[now] != d:
                    print("No")
                    exit()
            else:
                num[now] = d
                for node, Di in Tree[now]:
                    Q.append((node, d + Di))
print("Yes")

from collections import deque
import sys

input = sys.stdin.readline  # 文字列入力では注意！
N, M = list(map(int, input().split()))
Graph = [[] for _ in range(N)]
for _ in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    Graph[L].append((R, D))
    Graph[R].append((L, -D))
num = dict()
for i in range(N):
    if i not in num:
        num[i] = 0
        Q = deque(Graph[i])
        x = 0
        while Q:
            now, d = Q.popleft()
            if now in num:
                if num[now] != d:
                    print("No")
                    exit()
            else:
                num[now] = d
                for node, Di in Graph[now]:
                    Q.append((node, d + Di))
print("Yes")

+import sys +input = sys.stdin.readline  # 文字列入力では注意！ -Tree = [[] for _ in range(N)] +Graph = [[] for _ in range(N)] -    Tree[L].append((R, D)) -    Tree[R].append((L, -D)) +    Graph[L].append((R, D)) +    Graph[R].append((L, -D)) -        Q = deque(Tree[i]) +        Q = deque(Graph[i]) -                for node, Di in Tree[now]: +                for node, Di in Graph[now]: