import sys

sys.setrecursionlimit(100000)



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

LRD = [list(map(int, input().split())) for _ in range(M)]



graph = [{} for _ in range(N)]

for l, r, d in LRD:

	l, r = l - 1, r - 1

	graph[l][r] = d

	graph[r][l] = -d



visited = [False] * N

depths = [-1] * N

def dfs(v, p, d):

	if visited[v]:

		return True

	visited[v] = True

	depths[v] = d



	for n in graph[v]:

		if n == p:

			continue

		n_depth = d + graph[v][n]

		if depths[n] != -1 and depths[n] != n_depth:

			return False

		result = dfs(n, v, n_depth)

		if not result:

			return False

	return True



for n in range(N):

	if not dfs(n, -1, 0):

		print("No")

		break

else:

	print("Yes")

import sys

sys.setrecursionlimit(100000)



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

LRD = [list(map(int, input().split())) for _ in range(M)]



graph = [{} for _ in range(N)]

for l, r, d in LRD:

	l, r = l - 1, r - 1

	graph[l][r] = d

	graph[r][l] = -d



visited = [False] * N

depths = [0] * N

def dfs(v):

	q = [v]

	while q:

		cu = q.pop()

		for nx, d in list(graph[cu].items()):

			if visited[nx]:

				if depths[nx] != depths[cu] + d:

					return False

			else:

				visited[nx] = True

				depths[nx] = depths[cu] + d

				q += [nx]

	return True



for n in range(N):

	if not visited[n]:

		if not dfs(n):

			print("No")

			break

else:

	print("Yes")

import sys

sys.setrecursionlimit(100000)
N, M = list(map(int, input().split()))
LRD = [list(map(int, input().split())) for _ in range(M)]
graph = [{} for _ in range(N)]
for l, r, d in LRD:
    l, r = l - 1, r - 1
    graph[l][r] = d
    graph[r][l] = -d
visited = [False] * N
depths = [-1] * N


def dfs(v, p, d):
    if visited[v]:
        return True
    visited[v] = True
    depths[v] = d
    for n in graph[v]:
        if n == p:
            continue
        n_depth = d + graph[v][n]
        if depths[n] != -1 and depths[n] != n_depth:
            return False
        result = dfs(n, v, n_depth)
        if not result:
            return False
    return True


for n in range(N):
    if not dfs(n, -1, 0):
        print("No")
        break
else:
    print("Yes")

import sys

sys.setrecursionlimit(100000)
N, M = list(map(int, input().split()))
LRD = [list(map(int, input().split())) for _ in range(M)]
graph = [{} for _ in range(N)]
for l, r, d in LRD:
    l, r = l - 1, r - 1
    graph[l][r] = d
    graph[r][l] = -d
visited = [False] * N
depths = [0] * N


def dfs(v):
    q = [v]
    while q:
        cu = q.pop()
        for nx, d in list(graph[cu].items()):
            if visited[nx]:
                if depths[nx] != depths[cu] + d:
                    return False
            else:
                visited[nx] = True
                depths[nx] = depths[cu] + d
                q += [nx]
    return True


for n in range(N):
    if not visited[n]:
        if not dfs(n):
            print("No")
            break
else:
    print("Yes")

-depths = [-1] * N +depths = [0] * N -def dfs(v, p, d): -    if visited[v]: -        return True -    visited[v] = True -    depths[v] = d -    for n in graph[v]: -        if n == p: -            continue -        n_depth = d + graph[v][n] -        if depths[n] != -1 and depths[n] != n_depth: -            return False -        result = dfs(n, v, n_depth) -        if not result: -            return False +def dfs(v): +    q = [v] +    while q: +        cu = q.pop() +        for nx, d in list(graph[cu].items()): +            if visited[nx]: +                if depths[nx] != depths[cu] + d: +                    return False +            else: +                visited[nx] = True +                depths[nx] = depths[cu] + d +                q += [nx] -    if not dfs(n, -1, 0): -        print("No") -        break +    if not visited[n]: +        if not dfs(n): +            print("No") +            break