import sys

input = sys.stdin.readline



class Unionfind:

    __slots__ = ["nodes","diff_weight"]



    def __init__(self, n):

        self.nodes = [-1]*n

        self.diff_weight = [0]*n



    def root(self, x):

        if self.nodes[x] < 0:

            return x

        else:

            root_x = self.root(self.nodes[x])

            self.diff_weight[x] += self.diff_weight[self.nodes[x]]

            self.nodes[x] = root_x

            return root_x

    

    def unite(self, x, y, w=0):

        w += self.weight(x); w -= self.weight(y)

        x = self.root(x); y = self.root(y)

        if x == y:

            return

        rank_x = -self.nodes[x]; rank_y = -self.nodes[y]

        if rank_x < rank_y:

            x, y = y, x; w = -w

        if rank_x == rank_y:

            self.nodes[x] -= 1

        self.nodes[y] = x

        self.diff_weight[y] = w



    def weight(self, x):

        self.root(x)

        return self.diff_weight[x]

    

    def diff(self, x, y):

        return self.weight(y) - self.weight(x)

    

    def same(self, x, y):

        return self.root(x) == self.root(y)

    

    def rank(self, x):

        return -self.nodes[self.root(x)]

    

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

uf = Unionfind(N)

ans = "Yes"

for _ in range(M):

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

    L -= 1; R -= 1

    uf.unite(L, R, D)   

    if uf.diff(L, R) != D:

        ans = "No"

        break

print(ans)
import sys

input = sys.stdin.readline



class WeightedUnionfind:



    __slots__ = ['nodes','diff_weight']



    def __init__(self, n):

        self.nodes = [-1]*n

        self.diff_weight = [0]*n



    def root(self, x):

        if self.nodes[x] < 0:

            return x

        else:

            root_x = self.root(self.nodes[x])

            self.diff_weight[x] += self.diff_weight[self.nodes[x]]

            self.nodes[x] = root_x

            return root_x



    def unite(self, x, y, w=0):

        w += self.weight(x); w -= self.weight(y)

        x = self.root(x); y = self.root(y)

        if x == y:

            return

        rank_x = -self.nodes[x]; rank_y = -self.nodes[y]

        if rank_x < rank_y:

            x, y = y, x; w = -w

        if rank_x == rank_y:

            self.nodes[x] -= 1

        self.nodes[y] = x

        self.diff_weight[y] = w



    def weight(self, x):

        self.root(x)

        return self.diff_weight[x]



    def diff(self, x, y):

        return self.weight(y) - self.weight(x)



    def same(self, x, y):

        return self.root(x) == self.root(y)



    def rank(self, x):

        return -self.nodes[self.root(x)]



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

info = [list(map(int,input().split())) for i in range(M)]

wuf = WeightedUnionfind(N+1)

ans = "Yes"

for L,R,D in info:

    if wuf.same(L,R):

        if wuf.diff(L,R) != D:

            ans = "No"

        else:

            pass

    else:

        wuf.unite(L,R,D)

print(ans)
import sys

input = sys.stdin.readline


class Unionfind:
    __slots__ = ["nodes", "diff_weight"]

    def __init__(self, n):
        self.nodes = [-1] * n
        self.diff_weight = [0] * n

    def root(self, x):
        if self.nodes[x] < 0:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.diff_weight[x] += self.diff_weight[self.nodes[x]]
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y, w=0):
        w += self.weight(x)
        w -= self.weight(y)
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        rank_x = -self.nodes[x]
        rank_y = -self.nodes[y]
        if rank_x < rank_y:
            x, y = y, x
            w = -w
        if rank_x == rank_y:
            self.nodes[x] -= 1
        self.nodes[y] = x
        self.diff_weight[y] = w

    def weight(self, x):
        self.root(x)
        return self.diff_weight[x]

    def diff(self, x, y):
        return self.weight(y) - self.weight(x)

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def rank(self, x):
        return -self.nodes[self.root(x)]


N, M = list(map(int, input().split()))
uf = Unionfind(N)
ans = "Yes"
for _ in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    uf.unite(L, R, D)
    if uf.diff(L, R) != D:
        ans = "No"
        break
print(ans)

import sys

input = sys.stdin.readline


class WeightedUnionfind:
    __slots__ = ["nodes", "diff_weight"]

    def __init__(self, n):
        self.nodes = [-1] * n
        self.diff_weight = [0] * n

    def root(self, x):
        if self.nodes[x] < 0:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.diff_weight[x] += self.diff_weight[self.nodes[x]]
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y, w=0):
        w += self.weight(x)
        w -= self.weight(y)
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        rank_x = -self.nodes[x]
        rank_y = -self.nodes[y]
        if rank_x < rank_y:
            x, y = y, x
            w = -w
        if rank_x == rank_y:
            self.nodes[x] -= 1
        self.nodes[y] = x
        self.diff_weight[y] = w

    def weight(self, x):
        self.root(x)
        return self.diff_weight[x]

    def diff(self, x, y):
        return self.weight(y) - self.weight(x)

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def rank(self, x):
        return -self.nodes[self.root(x)]


N, M = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(M)]
wuf = WeightedUnionfind(N + 1)
ans = "Yes"
for L, R, D in info:
    if wuf.same(L, R):
        if wuf.diff(L, R) != D:
            ans = "No"
        else:
            pass
    else:
        wuf.unite(L, R, D)
print(ans)

-class Unionfind: +class WeightedUnionfind: -uf = Unionfind(N) +info = [list(map(int, input().split())) for i in range(M)] +wuf = WeightedUnionfind(N + 1) -for _ in range(M): -    L, R, D = list(map(int, input().split())) -    L -= 1 -    R -= 1 -    uf.unite(L, R, D) -    if uf.diff(L, R) != D: -        ans = "No" -        break +for L, R, D in info: +    if wuf.same(L, R): +        if wuf.diff(L, R) != D: +            ans = "No" +        else: +            pass +    else: +        wuf.unite(L, R, D)