import sys

from collections import deque



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





# https://at274.hatenablog.com/entry/2018/02/03/140504

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():

    N, M, *LRD = list(map(int, read().split()))



    uf = WeightedUnionFind(N)

    for l, r, d in zip(*[iter(LRD)] * 3):

        l -= 1

        r -= 1

        if uf.same(l, r) and uf.diff(l, r) != d:

            print('No')

            return

        else:

            uf.union(l, r, d)



    print('Yes')

    return





if __name__ == '__main__':

    main()

import sys

from collections import deque



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





class UnionFindWeighted:

    # Reference: https://note.nkmk.me/python-union-find/

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

        self.weight = [0] * n



    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            root = self.find(self.parents[x])

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

            self.parents[x] = root

            return root



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

        rx = self.find(x)

        ry = self.find(y)



        if rx == ry:

            return



        if self.parents[rx] > self.parents[ry]:

            x, y, rx, ry, w = y, x, ry, rx, -w



        self.parents[rx] += self.parents[ry]

        self.parents[ry] = rx

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



    def same(self, x, y):

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



    def diff(self, x, y):

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





def main():

    N, M, *LRD = list(map(int, read().split()))



    uf = UnionFindWeighted(N)

    for l, r, d in zip(*[iter(LRD)] * 3):

        l -= 1

        r -= 1

        if uf.same(l, r) and uf.diff(l, r) != d:

            print('No')

            return

        else:

            uf.union(l, r, d)



    print('Yes')

    return





if __name__ == '__main__':

    main()

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
# https://at274.hatenablog.com/entry/2018/02/03/140504
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():
    N, M, *LRD = list(map(int, read().split()))
    uf = WeightedUnionFind(N)
    for l, r, d in zip(*[iter(LRD)] * 3):
        l -= 1
        r -= 1
        if uf.same(l, r) and uf.diff(l, r) != d:
            print("No")
            return
        else:
            uf.union(l, r, d)
    print("Yes")
    return


if __name__ == "__main__":
    main()

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


class UnionFindWeighted:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            root = self.find(self.parents[x])
            self.weight[x] += self.weight[self.parents[x]]
            self.parents[x] = root
            return root

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if rx == ry:
            return
        if self.parents[rx] > self.parents[ry]:
            x, y, rx, ry, w = y, x, ry, rx, -w
        self.parents[rx] += self.parents[ry]
        self.parents[ry] = rx
        self.weight[ry] = self.weight[x] - self.weight[y] - w

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

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


def main():
    N, M, *LRD = list(map(int, read().split()))
    uf = UnionFindWeighted(N)
    for l, r, d in zip(*[iter(LRD)] * 3):
        l -= 1
        r -= 1
        if uf.same(l, r) and uf.diff(l, r) != d:
            print("No")
            return
        else:
            uf.union(l, r, d)
    print("Yes")
    return


if __name__ == "__main__":
    main()

-# https://at274.hatenablog.com/entry/2018/02/03/140504 -class WeightedUnionFind: + + +class UnionFindWeighted: +    # Reference: https://note.nkmk.me/python-union-find/ -        self.par = [i for i in range(n + 1)] -        self.rank = [0] * (n + 1) -        # 根への距離を管理 -        self.weight = [0] * (n + 1) +        self.n = n +        self.parents = [-1] * n +        self.weight = [0] * n -    # 検索 -        if self.par[x] == x: +        if self.parents[x] < 0: -            y = self.find(self.par[x]) -            # 親への重みを追加しながら根まで走査 -            self.weight[x] += self.weight[self.par[x]] -            self.par[x] = y -            return y +            root = self.find(self.parents[x]) +            self.weight[x] += self.weight[self.parents[x]] +            self.parents[x] = root +            return root -    # 併合 -        # 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 +        if rx == ry: +            return +        if self.parents[rx] > self.parents[ry]: +            x, y, rx, ry, w = y, x, ry, rx, -w +        self.parents[rx] += self.parents[ry] +        self.parents[ry] = rx +        self.weight[ry] = self.weight[x] - self.weight[y] - w -    # 同じ集合に属するか -    # xからyへのコスト -    uf = WeightedUnionFind(N) +    uf = UnionFindWeighted(N)