from collections import defaultdict

import sys

input = sys.stdin.readline

inf = float('INF')



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

if m == 0:

    print('Yes')

    exit()

edges = defaultdict(list)



for i in range(m):

    left, right, dist = list(map(int, input().split()))

    edges[left-1].append([right-1, dist])

    edges[right-1].append([left-1, -dist])



seen = [inf] * n

for node in range(n):

    if seen[node] != inf:

        continue



    seen[node] = 0

    todo = []

    while edges[node]:

        to, dis = edges[node].pop()

        todo.append([to, dis])

    while todo:

        new, dis = todo.pop()

        if seen[new] == inf:

            seen[new] = dis

        elif seen[new] != dis:

            print('No')

            exit()



        while edges[new]:

            to, n_dis = edges[new].pop()

            todo.append([to, dis + n_dis])



print('Yes')

from collections import defaultdict

import sys

input = sys.stdin.readline





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

if m == 0:

    print('Yes')

    exit()

edges = defaultdict(list)



for i in range(m):

    left, right, dist = list(map(int, input().split()))

    edges[left-1].append((right-1, dist))

    edges[right-1].append((left-1, -dist))



seen = [None] * n

for node in range(n):

    if seen[node] is not None:

        continue



    seen[node] = 0

    todo = []

    while edges[node]:

        to, dis = edges[node].pop()

        seen[to] = dis

        todo.append([to, dis])



    while todo:

        new, dis = todo.pop()



        while edges[new]:

            to, n_dis = edges[new].pop()

            if seen[to] is None:

                seen[to] = dis + n_dis

            elif seen[to] != dis + n_dis:

                print('No')

                exit()

            todo.append([to, dis + n_dis])



print('Yes')

from collections import defaultdict
import sys

input = sys.stdin.readline
inf = float("INF")
n, m = list(map(int, input().split()))
if m == 0:
    print("Yes")
    exit()
edges = defaultdict(list)
for i in range(m):
    left, right, dist = list(map(int, input().split()))
    edges[left - 1].append([right - 1, dist])
    edges[right - 1].append([left - 1, -dist])
seen = [inf] * n
for node in range(n):
    if seen[node] != inf:
        continue
    seen[node] = 0
    todo = []
    while edges[node]:
        to, dis = edges[node].pop()
        todo.append([to, dis])
    while todo:
        new, dis = todo.pop()
        if seen[new] == inf:
            seen[new] = dis
        elif seen[new] != dis:
            print("No")
            exit()
        while edges[new]:
            to, n_dis = edges[new].pop()
            todo.append([to, dis + n_dis])
print("Yes")

from collections import defaultdict
import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
if m == 0:
    print("Yes")
    exit()
edges = defaultdict(list)
for i in range(m):
    left, right, dist = list(map(int, input().split()))
    edges[left - 1].append((right - 1, dist))
    edges[right - 1].append((left - 1, -dist))
seen = [None] * n
for node in range(n):
    if seen[node] is not None:
        continue
    seen[node] = 0
    todo = []
    while edges[node]:
        to, dis = edges[node].pop()
        seen[to] = dis
        todo.append([to, dis])
    while todo:
        new, dis = todo.pop()
        while edges[new]:
            to, n_dis = edges[new].pop()
            if seen[to] is None:
                seen[to] = dis + n_dis
            elif seen[to] != dis + n_dis:
                print("No")
                exit()
            todo.append([to, dis + n_dis])
print("Yes")

-inf = float("INF") -    edges[left - 1].append([right - 1, dist]) -    edges[right - 1].append([left - 1, -dist]) -seen = [inf] * n +    edges[left - 1].append((right - 1, dist)) +    edges[right - 1].append((left - 1, -dist)) +seen = [None] * n -    if seen[node] != inf: +    if seen[node] is not None: +        seen[to] = dis -        if seen[new] == inf: -            seen[new] = dis -        elif seen[new] != dis: -            print("No") -            exit() +            if seen[to] is None: +                seen[to] = dis + n_dis +            elif seen[to] != dis + n_dis: +                print("No") +                exit()