from collections import deque



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

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

for _ in range(M):

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

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

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

X = [None] * N





def bfs(u):

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

    X[u] = 0

    while que:

        u, x = que.popleft()

        for nu, add in graph[u]:

            nx = x + add

            if X[nu] == nx:

                continue

            if X[nu] is not None and X[nu] != nx:

                print('No')

                exit()

            X[nu] = nx

            que.append((nu, nx))





for i in range(N):

    if X[i] is None:

        bfs(i)

print('Yes')

from collections import deque



n, m = list(map(int, input().split()))

tree = [[] for _ in range(n)]

for _ in range(m):

    L, R, D = list(map(int, input().split()))

    tree[L - 1].append((R - 1, D))

    tree[R - 1].append((L - 1, -D))

visited = [None for _ in range(n)]





def bfs(u):

    q = deque([[u, 0]])

    visited[u] = 0

    while q:

        u, dist = q.popleft()

        for next_u, d in tree[u]:

            next_x = dist + d

            if visited[next_u] is None:

                visited[next_u] = next_x

                q.append([next_u, next_x])

            elif visited[next_u] == next_x:

                continue

            else:

                print("No")

                exit()





for i in range(n):

    if visited[i] is None:

        bfs(i)

else:

    print('Yes')

from collections import deque

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


def bfs(u):
    que = deque([(u, 0)])
    X[u] = 0
    while que:
        u, x = que.popleft()
        for nu, add in graph[u]:
            nx = x + add
            if X[nu] == nx:
                continue
            if X[nu] is not None and X[nu] != nx:
                print("No")
                exit()
            X[nu] = nx
            que.append((nu, nx))


for i in range(N):
    if X[i] is None:
        bfs(i)
print("Yes")

from collections import deque

n, m = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for _ in range(m):
    L, R, D = list(map(int, input().split()))
    tree[L - 1].append((R - 1, D))
    tree[R - 1].append((L - 1, -D))
visited = [None for _ in range(n)]


def bfs(u):
    q = deque([[u, 0]])
    visited[u] = 0
    while q:
        u, dist = q.popleft()
        for next_u, d in tree[u]:
            next_x = dist + d
            if visited[next_u] is None:
                visited[next_u] = next_x
                q.append([next_u, next_x])
            elif visited[next_u] == next_x:
                continue
            else:
                print("No")
                exit()


for i in range(n):
    if visited[i] is None:
        bfs(i)
else:
    print("Yes")

-N, M = list(map(int, input().split())) -graph = [[] for _ in range(N)] -for _ in range(M): -    l, r, d = list(map(int, input().split())) -    graph[l - 1].append([r - 1, d]) -    graph[r - 1].append([l - 1, -d]) -X = [None] * N +n, m = list(map(int, input().split())) +tree = [[] for _ in range(n)] +for _ in range(m): +    L, R, D = list(map(int, input().split())) +    tree[L - 1].append((R - 1, D)) +    tree[R - 1].append((L - 1, -D)) +visited = [None for _ in range(n)] -    que = deque([(u, 0)]) -    X[u] = 0 -    while que: -        u, x = que.popleft() -        for nu, add in graph[u]: -            nx = x + add -            if X[nu] == nx: +    q = deque([[u, 0]]) +    visited[u] = 0 +    while q: +        u, dist = q.popleft() +        for next_u, d in tree[u]: +            next_x = dist + d +            if visited[next_u] is None: +                visited[next_u] = next_x +                q.append([next_u, next_x]) +            elif visited[next_u] == next_x: -            if X[nu] is not None and X[nu] != nx: +            else: -            X[nu] = nx -            que.append((nu, nx)) -for i in range(N): -    if X[i] is None: +for i in range(n): +    if visited[i] is None: -print("Yes") +else: +    print("Yes")