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

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

D = [0] * N

C = [1] * N



def par(a):

    if a == P[a]:

        return a

    p = par(P[a])

    d = D[P[a]]

    P[a] = p

    D[a] += d

    return p



def dist(a, b):

    pa = par(a)

    pb = par(b)

    if pa == pb:

        return D[b] - D[a]

    return 1 << 30



def unite(a, b, d):

    if par(a) == par(b):

        return

    if C[P[a]] < C[P[b]]:

        a, b, d = b, a, -d

    C[P[a]] += C[P[b]]

    D[P[b]] = D[a] + d - D[b]

    P[P[b]] = P[a]



for _ in range(M):

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

    l, r = l-1, r-1

    dd = dist(l, r)

    if dd == 1<<30:

        unite(l, r, d)

    else:

        if d != dd:

            print("No")

            break

else:

    print("Yes")
from collections import deque

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

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

for _ in range(M):

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

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

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



done = [0] * N

dist = [0] * N

def BFS(i):

    Q = deque([i])

    done[i] = 1

    while Q:

        x = Q.popleft()

        for y, d in X[x]:

            if done[y]:

                if dist[y] != dist[x] + d:

                    return 0

            else:

                done[y] = 1

                dist[y] = dist[x] + d

                Q.append(y)

    return 1



for i in range(N):

    if done[i] == 0:

        if BFS(i) == 0:

            print("No")

            break

else:

    print("Yes")
N, M = list(map(int, input().split()))
P = [i for i in range(N)]
D = [0] * N
C = [1] * N


def par(a):
    if a == P[a]:
        return a
    p = par(P[a])
    d = D[P[a]]
    P[a] = p
    D[a] += d
    return p


def dist(a, b):
    pa = par(a)
    pb = par(b)
    if pa == pb:
        return D[b] - D[a]
    return 1 << 30


def unite(a, b, d):
    if par(a) == par(b):
        return
    if C[P[a]] < C[P[b]]:
        a, b, d = b, a, -d
    C[P[a]] += C[P[b]]
    D[P[b]] = D[a] + d - D[b]
    P[P[b]] = P[a]


for _ in range(M):
    l, r, d = list(map(int, input().split()))
    l, r = l - 1, r - 1
    dd = dist(l, r)
    if dd == 1 << 30:
        unite(l, r, d)
    else:
        if d != dd:
            print("No")
            break
else:
    print("Yes")

from collections import deque

N, M = list(map(int, input().split()))
X = [[] for _ in range(N)]
for _ in range(M):
    l, r, d = list(map(int, input().split()))
    X[l - 1].append((r - 1, d))
    X[r - 1].append((l - 1, -d))
done = [0] * N
dist = [0] * N


def BFS(i):
    Q = deque([i])
    done[i] = 1
    while Q:
        x = Q.popleft()
        for y, d in X[x]:
            if done[y]:
                if dist[y] != dist[x] + d:
                    return 0
            else:
                done[y] = 1
                dist[y] = dist[x] + d
                Q.append(y)
    return 1


for i in range(N):
    if done[i] == 0:
        if BFS(i) == 0:
            print("No")
            break
else:
    print("Yes")

+from collections import deque + -P = [i for i in range(N)] -D = [0] * N -C = [1] * N +X = [[] for _ in range(N)] +for _ in range(M): +    l, r, d = list(map(int, input().split())) +    X[l - 1].append((r - 1, d)) +    X[r - 1].append((l - 1, -d)) +done = [0] * N +dist = [0] * N -def par(a): -    if a == P[a]: -        return a -    p = par(P[a]) -    d = D[P[a]] -    P[a] = p -    D[a] += d -    return p +def BFS(i): +    Q = deque([i]) +    done[i] = 1 +    while Q: +        x = Q.popleft() +        for y, d in X[x]: +            if done[y]: +                if dist[y] != dist[x] + d: +                    return 0 +            else: +                done[y] = 1 +                dist[y] = dist[x] + d +                Q.append(y) +    return 1 -def dist(a, b): -    pa = par(a) -    pb = par(b) -    if pa == pb: -        return D[b] - D[a] -    return 1 << 30 - - -def unite(a, b, d): -    if par(a) == par(b): -        return -    if C[P[a]] < C[P[b]]: -        a, b, d = b, a, -d -    C[P[a]] += C[P[b]] -    D[P[b]] = D[a] + d - D[b] -    P[P[b]] = P[a] - - -for _ in range(M): -    l, r, d = list(map(int, input().split())) -    l, r = l - 1, r - 1 -    dd = dist(l, r) -    if dd == 1 << 30: -        unite(l, r, d) -    else: -        if d != dd: +for i in range(N): +    if done[i] == 0: +        if BFS(i) == 0: