def root(v):

    if par[v] == v:

        return v

    r = root(par[v])

    diff_weight[v] += diff_weight[par[v]]

    par[v] = r

    return r



def weight(v):

    root(v)

    return diff_weight[v]



def diff(u, v):

    return weight(v) - weight(u)



def unite(u, v, w):

    w += diff(v, u)

    u = root(u)

    v = root(v)

    if u == v:

        return

    if rank[u] < rank[v]:

        u, v = v, u

        w = -w

    par[v] = u

    diff_weight[v] = w

    if rank[u] == rank[v]:

        rank[u] += 1



def same(u, v):

    return root(u) == root(v)



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

par = list(range(N))

rank = [0] * N

diff_weight = [0] * N

for _ in range(M):

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

    l -= 1

    r -= 1

    if same(l, r):

        dist = diff(l, r)

        if dist != d:

            print("No")

            exit()

    else:

        unite(l, r, d)



print("Yes")
from collections import deque

import sys

input = sys.stdin.readline



def bfs(s):

    que = deque([(0, s)])

    while que:

        d, v = que.popleft()

        if visited[v]:

            if d != dist[v]:

                return False

            continue

        visited[v] = True

        dist[v] = d

        for w, u in A[v]:

            que.append((d + w, u))

    return True



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

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

for _ in range(M):

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

    l -= 1

    r -= 1

    A[l].append((w, r))

    A[r].append((-w, l))

visited = [0] * N

dist = [0] * N

res = 'Yes'

for i in range(N):

    if visited[i]:

        continue

    f = bfs(i)

    if not f:

        res = 'No'

print(res)
def root(v):
    if par[v] == v:
        return v
    r = root(par[v])
    diff_weight[v] += diff_weight[par[v]]
    par[v] = r
    return r


def weight(v):
    root(v)
    return diff_weight[v]


def diff(u, v):
    return weight(v) - weight(u)


def unite(u, v, w):
    w += diff(v, u)
    u = root(u)
    v = root(v)
    if u == v:
        return
    if rank[u] < rank[v]:
        u, v = v, u
        w = -w
    par[v] = u
    diff_weight[v] = w
    if rank[u] == rank[v]:
        rank[u] += 1


def same(u, v):
    return root(u) == root(v)


N, M = list(map(int, input().split()))
par = list(range(N))
rank = [0] * N
diff_weight = [0] * N
for _ in range(M):
    l, r, d = list(map(int, input().split()))
    l -= 1
    r -= 1
    if same(l, r):
        dist = diff(l, r)
        if dist != d:
            print("No")
            exit()
    else:
        unite(l, r, d)
print("Yes")

from collections import deque
import sys

input = sys.stdin.readline


def bfs(s):
    que = deque([(0, s)])
    while que:
        d, v = que.popleft()
        if visited[v]:
            if d != dist[v]:
                return False
            continue
        visited[v] = True
        dist[v] = d
        for w, u in A[v]:
            que.append((d + w, u))
    return True


N, M = list(map(int, input().split()))
A = [[] for _ in range(N)]
for _ in range(M):
    l, r, w = list(map(int, input().split()))
    l -= 1
    r -= 1
    A[l].append((w, r))
    A[r].append((-w, l))
visited = [0] * N
dist = [0] * N
res = "Yes"
for i in range(N):
    if visited[i]:
        continue
    f = bfs(i)
    if not f:
        res = "No"
print(res)

-def root(v): -    if par[v] == v: -        return v -    r = root(par[v]) -    diff_weight[v] += diff_weight[par[v]] -    par[v] = r -    return r +from collections import deque +import sys + +input = sys.stdin.readline -def weight(v): -    root(v) -    return diff_weight[v] - - -def diff(u, v): -    return weight(v) - weight(u) - - -def unite(u, v, w): -    w += diff(v, u) -    u = root(u) -    v = root(v) -    if u == v: -        return -    if rank[u] < rank[v]: -        u, v = v, u -        w = -w -    par[v] = u -    diff_weight[v] = w -    if rank[u] == rank[v]: -        rank[u] += 1 - - -def same(u, v): -    return root(u) == root(v) +def bfs(s): +    que = deque([(0, s)]) +    while que: +        d, v = que.popleft() +        if visited[v]: +            if d != dist[v]: +                return False +            continue +        visited[v] = True +        dist[v] = d +        for w, u in A[v]: +            que.append((d + w, u)) +    return True -par = list(range(N)) -rank = [0] * N -diff_weight = [0] * N +A = [[] for _ in range(N)] -    l, r, d = list(map(int, input().split())) +    l, r, w = list(map(int, input().split())) -    if same(l, r): -        dist = diff(l, r) -        if dist != d: -            print("No") -            exit() -    else: -        unite(l, r, d) -print("Yes") +    A[l].append((w, r)) +    A[r].append((-w, l)) +visited = [0] * N +dist = [0] * N +res = "Yes" +for i in range(N): +    if visited[i]: +        continue +    f = bfs(i) +    if not f: +        res = "No" +print(res)