import sys

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline



def dfs(v, d):

    if visited[v] and X[v] != d:

        return False

    if visited[v] and X[v] == d:

        return True

    visited[v] = True

    X[v] = d

    for u, c in E[v]:

        if not dfs(u, d + c):

            return False

    return True



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

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

for _ in range(M):

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

    l -= 1

    r -= 1

    E[l].append((r, d))

    E[r].append((l, -d))

X = [None] * N

visited = [False] * N

for v in range(N):

    if not visited[v]:

        if not dfs(v, 0):

            print('No')

            exit()

print('Yes')

from collections import deque



def dfs(s):

    stack = deque([s])

    dist[s] = 0

    while stack:

        v = stack.pop()

        for d, u in E[v]:

            if dist[u] is None:

                dist[u] = dist[v] + d

                stack.append(u)

            else:

                if dist[u] != dist[v] + d:

                    return False

    return True



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

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

for _ in range(M):

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

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

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

dist = [None] * N

for i in range(N):

    if dist[i] is not None:

        continue

    if not dfs(i):

        print('No')

        break

else:

    print('Yes')
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def dfs(v, d):
    if visited[v] and X[v] != d:
        return False
    if visited[v] and X[v] == d:
        return True
    visited[v] = True
    X[v] = d
    for u, c in E[v]:
        if not dfs(u, d + c):
            return False
    return True


N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
    l, r, d = list(map(int, input().split()))
    l -= 1
    r -= 1
    E[l].append((r, d))
    E[r].append((l, -d))
X = [None] * N
visited = [False] * N
for v in range(N):
    if not visited[v]:
        if not dfs(v, 0):
            print("No")
            exit()
print("Yes")

from collections import deque


def dfs(s):
    stack = deque([s])
    dist[s] = 0
    while stack:
        v = stack.pop()
        for d, u in E[v]:
            if dist[u] is None:
                dist[u] = dist[v] + d
                stack.append(u)
            else:
                if dist[u] != dist[v] + d:
                    return False
    return True


N, M = list(map(int, input().split()))
E = [[] for _ in range(N)]
for _ in range(M):
    l, r, d = list(map(int, input().split()))
    E[l - 1].append((d, r - 1))
    E[r - 1].append((-d, l - 1))
dist = [None] * N
for i in range(N):
    if dist[i] is not None:
        continue
    if not dfs(i):
        print("No")
        break
else:
    print("Yes")

-import sys - -sys.setrecursionlimit(10**6) -input = sys.stdin.readline +from collections import deque -def dfs(v, d): -    if visited[v] and X[v] != d: -        return False -    if visited[v] and X[v] == d: -        return True -    visited[v] = True -    X[v] = d -    for u, c in E[v]: -        if not dfs(u, d + c): -            return False +def dfs(s): +    stack = deque([s]) +    dist[s] = 0 +    while stack: +        v = stack.pop() +        for d, u in E[v]: +            if dist[u] is None: +                dist[u] = dist[v] + d +                stack.append(u) +            else: +                if dist[u] != dist[v] + d: +                    return False -    l -= 1 -    r -= 1 -    E[l].append((r, d)) -    E[r].append((l, -d)) -X = [None] * N -visited = [False] * N -for v in range(N): -    if not visited[v]: -        if not dfs(v, 0): -            print("No") -            exit() -print("Yes") +    E[l - 1].append((d, r - 1)) +    E[r - 1].append((-d, l - 1)) +dist = [None] * N +for i in range(N): +    if dist[i] is not None: +        continue +    if not dfs(i): +        print("No") +        break +else: +    print("Yes")