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

LRD = [tuple(int(x) for x in input().split()) for _ in range(M)]

Graph = [[] for _ in range(N)]

for l,r,d in LRD:

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

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



seen = set()

Dfr = [0] * N #dist from Root

for root in range(N):

    if root in seen: continue

    seen.add(root)

    V = [root]

    while len(V) != 0: #bfs

        v = V.pop(0)

        for nv,d in Graph[v]:

            if nv in seen and Dfr[nv] != Dfr[v] + d: #bfsで発見済みの値が異なる⇔矛盾

                print('No')

                exit()

            if nv in seen: continue

            else:

                seen.add(nv)

                Dfr[nv] = Dfr[v] + d

                V.append(nv)

print('Yes')
from collections import namedtuple, deque



class Person:

    def __init__(self, id, conn, x):

        self.id = id

        self.conn = conn

        self.x = x



def main():

    with open(0) as f:

        N, M = list(map(int, f.readline().split()))

        info = [tuple(map(int, line.split())) for line in f.readlines()]

    people = [Person(i, conn=[], x=None) for i in range(N)]

    for l, r, d in info:

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

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

    

    for person in people:

        if person.x is not None:

            continue

        else:

            person.x = person.id

            #bfs

            reserved = deque([person])

            seen = {person.id}

            while len(reserved) > 0:

                current = reserved.popleft()

                for next_person_id, d in current.conn:

                    if people[next_person_id].x is None:

                        people[next_person_id].x = current.x + d

                    else:

                        if people[next_person_id].x != current.x + d:

                            print('No')

                            return None

                    if next_person_id in seen:

                        continue

                    seen.add(next_person_id)

                    reserved.append(people[next_person_id])

    print('Yes')



main()            
N, M = list(map(int, input().split()))
LRD = [tuple(int(x) for x in input().split()) for _ in range(M)]
Graph = [[] for _ in range(N)]
for l, r, d in LRD:
    Graph[r - 1].append((l - 1, d))
    Graph[l - 1].append((r - 1, -d))
seen = set()
Dfr = [0] * N  # dist from Root
for root in range(N):
    if root in seen:
        continue
    seen.add(root)
    V = [root]
    while len(V) != 0:  # bfs
        v = V.pop(0)
        for nv, d in Graph[v]:
            if nv in seen and Dfr[nv] != Dfr[v] + d:  # bfsで発見済みの値が異なる⇔矛盾
                print("No")
                exit()
            if nv in seen:
                continue
            else:
                seen.add(nv)
                Dfr[nv] = Dfr[v] + d
                V.append(nv)
print("Yes")

from collections import namedtuple, deque


class Person:
    def __init__(self, id, conn, x):
        self.id = id
        self.conn = conn
        self.x = x


def main():
    with open(0) as f:
        N, M = list(map(int, f.readline().split()))
        info = [tuple(map(int, line.split())) for line in f.readlines()]
    people = [Person(i, conn=[], x=None) for i in range(N)]
    for l, r, d in info:
        people[l - 1].conn.append((r - 1, d))
        people[r - 1].conn.append((l - 1, -d))
    for person in people:
        if person.x is not None:
            continue
        else:
            person.x = person.id
            # bfs
            reserved = deque([person])
            seen = {person.id}
            while len(reserved) > 0:
                current = reserved.popleft()
                for next_person_id, d in current.conn:
                    if people[next_person_id].x is None:
                        people[next_person_id].x = current.x + d
                    else:
                        if people[next_person_id].x != current.x + d:
                            print("No")
                            return None
                    if next_person_id in seen:
                        continue
                    seen.add(next_person_id)
                    reserved.append(people[next_person_id])
    print("Yes")


main()

-N, M = list(map(int, input().split())) -LRD = [tuple(int(x) for x in input().split()) for _ in range(M)] -Graph = [[] for _ in range(N)] -for l, r, d in LRD: -    Graph[r - 1].append((l - 1, d)) -    Graph[l - 1].append((r - 1, -d)) -seen = set() -Dfr = [0] * N  # dist from Root -for root in range(N): -    if root in seen: -        continue -    seen.add(root) -    V = [root] -    while len(V) != 0:  # bfs -        v = V.pop(0) -        for nv, d in Graph[v]: -            if nv in seen and Dfr[nv] != Dfr[v] + d:  # bfsで発見済みの値が異なる⇔矛盾 -                print("No") -                exit() -            if nv in seen: -                continue -            else: -                seen.add(nv) -                Dfr[nv] = Dfr[v] + d -                V.append(nv) -print("Yes") +from collections import namedtuple, deque + + +class Person: +    def __init__(self, id, conn, x): +        self.id = id +        self.conn = conn +        self.x = x + + +def main(): +    with open(0) as f: +        N, M = list(map(int, f.readline().split())) +        info = [tuple(map(int, line.split())) for line in f.readlines()] +    people = [Person(i, conn=[], x=None) for i in range(N)] +    for l, r, d in info: +        people[l - 1].conn.append((r - 1, d)) +        people[r - 1].conn.append((l - 1, -d)) +    for person in people: +        if person.x is not None: +            continue +        else: +            person.x = person.id +            # bfs +            reserved = deque([person]) +            seen = {person.id} +            while len(reserved) > 0: +                current = reserved.popleft() +                for next_person_id, d in current.conn: +                    if people[next_person_id].x is None: +                        people[next_person_id].x = current.x + d +                    else: +                        if people[next_person_id].x != current.x + d: +                            print("No") +                            return None +                    if next_person_id in seen: +                        continue +                    seen.add(next_person_id) +                    reserved.append(people[next_person_id]) +    print("Yes") + + +main()