class WeightedUnionFind:

    def __init__(self, n):

        self.par = [i for i in range(n+1)]

        self.rank = [0] * (n+1)

        # 根への距離を管理

        self.weight = [0] * (n+1)



    # 検索

    def find(self, x):

        if self.par[x] == x:

            return x

        else:

            y = self.find(self.par[x])

            # 親への重みを追加しながら根まで走査

            self.weight[x] += self.weight[self.par[x]]

            self.par[x] = y

            return y



    # 併合

    def union(self, x, y, w):

        rx = self.find(x)

        ry = self.find(y)

        # xの木の高さ < yの木の高さ

        if self.rank[rx] < self.rank[ry]:

            self.par[rx] = ry

            self.weight[rx] = w - self.weight[x] + self.weight[y]

        # xの木の高さ ≧ yの木の高さ

        else:

            self.par[ry] = rx

            self.weight[ry] = -w - self.weight[y] + self.weight[x]

            # 木の高さが同じだった場合の処理

            if self.rank[rx] == self.rank[ry]:

                self.rank[rx] += 1



    # 同じ集合に属するか

    def same(self, x, y):

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



    # xからyへのコスト

    def diff(self, x, y):

        return self.weight[x] - self.weight[y]



def main():

    max_v, max_e = list(map(int, input().split()))

    uf = WeightedUnionFind(max_v)

    k = []

    s = 0

    for i in range(max_e):

        a,b,w= list(map(int, input().split()))

        a-=1

        b-=1

        if uf.same(a,b):

            if w != uf.diff(a,b):

                print("No")

                break

        else:

            uf.union(a,b,w)

    else:

        print("Yes")

if __name__ == '__main__':

    main()

 
def main():

    import sys

    input = sys.stdin.readline



    def find(x):

        if par[x] < 0:

            return x

        else:

            px = find(par[x])

            wei[x] += wei[par[x]]

            par[x] = px

            return px



    def weight(x):

        find(x)

        return wei[x]





    def unite(x,y,w):

        w += wei[x]-wei[y]

        x = find(x)

        y = find(y)

        

        if x == y:

            return False

        else:

            if par[x] > par[y]:

                x,y = y,x

                w = -w

            par[x] += par[y]

            par[y] = x

            wei[y] = w

            return True



    def same(x,y):

        return find(x) == find(y)



    def size(x):

        return -par[find(x)]



    def diff(x,y):

        return weight(y)-weight(x)



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





    par = [-1]*n

    wei = [0]*n



    for i in range(m):

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

        l,r = l-1,r-1

        if same(l,r):

            if d != diff(l,r):

                print('No')

                exit()

        else:

            unite(l,r,d)

    print('Yes')

            

if __name__ == '__main__':

    main()
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        # 根への距離を管理
        self.weight = [0] * (n + 1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


def main():
    max_v, max_e = list(map(int, input().split()))
    uf = WeightedUnionFind(max_v)
    k = []
    s = 0
    for i in range(max_e):
        a, b, w = list(map(int, input().split()))
        a -= 1
        b -= 1
        if uf.same(a, b):
            if w != uf.diff(a, b):
                print("No")
                break
        else:
            uf.union(a, b, w)
    else:
        print("Yes")


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline

    def find(x):
        if par[x] < 0:
            return x
        else:
            px = find(par[x])
            wei[x] += wei[par[x]]
            par[x] = px
            return px

    def weight(x):
        find(x)
        return wei[x]

    def unite(x, y, w):
        w += wei[x] - wei[y]
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x, y = y, x
                w = -w
            par[x] += par[y]
            par[y] = x
            wei[y] = w
            return True

    def same(x, y):
        return find(x) == find(y)

    def size(x):
        return -par[find(x)]

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

    n, m = list(map(int, input().split()))
    par = [-1] * n
    wei = [0] * n
    for i in range(m):
        l, r, d = list(map(int, input().split()))
        l, r = l - 1, r - 1
        if same(l, r):
            if d != diff(l, r):
                print("No")
                exit()
        else:
            unite(l, r, d)
    print("Yes")


if __name__ == "__main__":
    main()

-class WeightedUnionFind: -    def __init__(self, n): -        self.par = [i for i in range(n + 1)] -        self.rank = [0] * (n + 1) -        # 根への距離を管理 -        self.weight = [0] * (n + 1) +def main(): +    import sys -    # 検索 -    def find(self, x): -        if self.par[x] == x: +    input = sys.stdin.readline + +    def find(x): +        if par[x] < 0: -            y = self.find(self.par[x]) -            # 親への重みを追加しながら根まで走査 -            self.weight[x] += self.weight[self.par[x]] -            self.par[x] = y -            return y +            px = find(par[x]) +            wei[x] += wei[par[x]] +            par[x] = px +            return px -    # 併合 -    def union(self, x, y, w): -        rx = self.find(x) -        ry = self.find(y) -        # xの木の高さ < yの木の高さ -        if self.rank[rx] < self.rank[ry]: -            self.par[rx] = ry -            self.weight[rx] = w - self.weight[x] + self.weight[y] -        # xの木の高さ ≧ yの木の高さ +    def weight(x): +        find(x) +        return wei[x] + +    def unite(x, y, w): +        w += wei[x] - wei[y] +        x = find(x) +        y = find(y) +        if x == y: +            return False -            self.par[ry] = rx -            self.weight[ry] = -w - self.weight[y] + self.weight[x] -            # 木の高さが同じだった場合の処理 -            if self.rank[rx] == self.rank[ry]: -                self.rank[rx] += 1 +            if par[x] > par[y]: +                x, y = y, x +                w = -w +            par[x] += par[y] +            par[y] = x +            wei[y] = w +            return True -    # 同じ集合に属するか -    def same(self, x, y): -        return self.find(x) == self.find(y) +    def same(x, y): +        return find(x) == find(y) -    # xからyへのコスト -    def diff(self, x, y): -        return self.weight[x] - self.weight[y] +    def size(x): +        return -par[find(x)] +    def diff(x, y): +        return weight(y) - weight(x) -def main(): -    max_v, max_e = list(map(int, input().split())) -    uf = WeightedUnionFind(max_v) -    k = [] -    s = 0 -    for i in range(max_e): -        a, b, w = list(map(int, input().split())) -        a -= 1 -        b -= 1 -        if uf.same(a, b): -            if w != uf.diff(a, b): +    n, m = list(map(int, input().split())) +    par = [-1] * n +    wei = [0] * n +    for i in range(m): +        l, r, d = list(map(int, input().split())) +        l, r = l - 1, r - 1 +        if same(l, r): +            if d != diff(l, r): -                break +                exit() -            uf.union(a, b, w) -    else: -        print("Yes") +            unite(l, r, d) +    print("Yes")