import sys

sys.setrecursionlimit(100000000)



def main():

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

    e = [[] for i in range(N)]

    t = 0

    a = []

    for i in range(M):

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

        e[r-1].append([l-1,d])

        e[l-1].append([r-1,-d])

        a.append(r-1)

        a.append(l-1)

        t = r-1



    col = [ float("inf") for i in range(N) ]

    def dfs(i,c):



        for node in e[i]:

            if col[node[0]] == float("inf"):

                col[node[0]] = c + node[1]

                dfs(node[0],c+node[1])

            elif col[node[0]] != c + node[1]:

                print("No")

                exit()





    dfs(t,0)

    a = list(set(a))

    for i in a:

        if col[i] == float("inf"):

            dfs(i,0)





    print("Yes")





if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(100000000)



def main():

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

    e = [[] for i in range(N)]

    t = 0

    a = []

    for i in range(M):

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

        e[r-1].append((l-1,d))

        e[l-1].append((r-1,-d))

        a.append(r-1)

        a.append(l-1)

        t = r-1



    col = [ float("inf") for i in range(N) ]

    def dfs(i,c):

        for node in e[i]:

            if col[node[0]] == float("inf"):

                col[node[0]] = c + node[1]

                dfs(node[0],c+node[1])

            elif col[node[0]] != c + node[1]:

                print("No")

                exit()





    dfs(t,0)

    a = list(set(a))

    for i in a:

        if col[i] == float("inf"):

            dfs(i,0)





    print("Yes")





if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(100000000)


def main():
    N, M = list(map(int, input().split()))
    e = [[] for i in range(N)]
    t = 0
    a = []
    for i in range(M):
        r, l, d = list(map(int, input().split()))
        e[r - 1].append([l - 1, d])
        e[l - 1].append([r - 1, -d])
        a.append(r - 1)
        a.append(l - 1)
        t = r - 1
    col = [float("inf") for i in range(N)]

    def dfs(i, c):
        for node in e[i]:
            if col[node[0]] == float("inf"):
                col[node[0]] = c + node[1]
                dfs(node[0], c + node[1])
            elif col[node[0]] != c + node[1]:
                print("No")
                exit()

    dfs(t, 0)
    a = list(set(a))
    for i in a:
        if col[i] == float("inf"):
            dfs(i, 0)
    print("Yes")


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(100000000)


def main():
    N, M = list(map(int, input().split()))
    e = [[] for i in range(N)]
    t = 0
    a = []
    for i in range(M):
        r, l, d = list(map(int, input().split()))
        e[r - 1].append((l - 1, d))
        e[l - 1].append((r - 1, -d))
        a.append(r - 1)
        a.append(l - 1)
        t = r - 1
    col = [float("inf") for i in range(N)]

    def dfs(i, c):
        for node in e[i]:
            if col[node[0]] == float("inf"):
                col[node[0]] = c + node[1]
                dfs(node[0], c + node[1])
            elif col[node[0]] != c + node[1]:
                print("No")
                exit()

    dfs(t, 0)
    a = list(set(a))
    for i in a:
        if col[i] == float("inf"):
            dfs(i, 0)
    print("Yes")


if __name__ == "__main__":
    main()

-        e[r - 1].append([l - 1, d]) -        e[l - 1].append([r - 1, -d]) +        e[r - 1].append((l - 1, d)) +        e[l - 1].append((r - 1, -d))