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

L = [0]*M

R = [0]*M

D = [0]*M

for i in range(M):

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

    

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

for i in range(M):

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

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

    

ans = "Yes"

visited = ["?"]*N

for i in range(N):

    if visited[i] == "?":

        q = [[i, 0]]

        visited[i] = 0

        while len(q) > 0:

            temp = q.pop(-1)

            pos = temp[0]

            d = temp[1]

            for j in range(len(G[pos])):

                if visited[G[pos][j][0]] == "?":

                    q.append([G[pos][j][0], d+G[pos][j][1]])

                    visited[G[pos][j][0]] = d+G[pos][j][1]

                elif visited[G[pos][j][0]] != d+G[pos][j][1]:

                    ans = "No"

                    break



print(ans)
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((r-1, d))

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



from collections import deque

human = ["0"]*N

ans = "Yes"

for i in range(N):

    if ans == "No":

        break

    if len(E[i]) == 0:

        continue

    if human[i] == "0":

        human[i] = 0

        q = deque([i])

        while q:

            temp = q.popleft()

            for e in E[temp]:

                if human[e[0]] == "0":

                    human[e[0]] = human[temp]+e[1]

                    q.append(e[0])

                elif human[e[0]] != human[temp]+e[1]:

                    ans = "No"

                    break

    else:

        for e in E[i]:

            if human[e[0]] != human[i]+e[1]:

                ans = "No"

                break



print(ans)
N, M = list(map(int, input().split()))
L = [0] * M
R = [0] * M
D = [0] * M
for i in range(M):
    L[i], R[i], D[i] = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
    G[L[i] - 1].append([R[i] - 1, D[i]])
    G[R[i] - 1].append([L[i] - 1, -D[i]])
ans = "Yes"
visited = ["?"] * N
for i in range(N):
    if visited[i] == "?":
        q = [[i, 0]]
        visited[i] = 0
        while len(q) > 0:
            temp = q.pop(-1)
            pos = temp[0]
            d = temp[1]
            for j in range(len(G[pos])):
                if visited[G[pos][j][0]] == "?":
                    q.append([G[pos][j][0], d + G[pos][j][1]])
                    visited[G[pos][j][0]] = d + G[pos][j][1]
                elif visited[G[pos][j][0]] != d + G[pos][j][1]:
                    ans = "No"
                    break
print(ans)

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((r - 1, d))
    E[r - 1].append((l - 1, -d))
from collections import deque

human = ["0"] * N
ans = "Yes"
for i in range(N):
    if ans == "No":
        break
    if len(E[i]) == 0:
        continue
    if human[i] == "0":
        human[i] = 0
        q = deque([i])
        while q:
            temp = q.popleft()
            for e in E[temp]:
                if human[e[0]] == "0":
                    human[e[0]] = human[temp] + e[1]
                    q.append(e[0])
                elif human[e[0]] != human[temp] + e[1]:
                    ans = "No"
                    break
    else:
        for e in E[i]:
            if human[e[0]] != human[i] + e[1]:
                ans = "No"
                break
print(ans)

-L = [0] * M -R = [0] * M -D = [0] * M -for i in range(M): -    L[i], R[i], D[i] = list(map(int, input().split())) -G = [[] for _ in range(N)] -for i in range(M): -    G[L[i] - 1].append([R[i] - 1, D[i]]) -    G[R[i] - 1].append([L[i] - 1, -D[i]]) +E = [[] for _ in range(N)] +for _ in range(M): +    l, r, d = list(map(int, input().split())) +    E[l - 1].append((r - 1, d)) +    E[r - 1].append((l - 1, -d)) +from collections import deque + +human = ["0"] * N -visited = ["?"] * N -    if visited[i] == "?": -        q = [[i, 0]] -        visited[i] = 0 -        while len(q) > 0: -            temp = q.pop(-1) -            pos = temp[0] -            d = temp[1] -            for j in range(len(G[pos])): -                if visited[G[pos][j][0]] == "?": -                    q.append([G[pos][j][0], d + G[pos][j][1]]) -                    visited[G[pos][j][0]] = d + G[pos][j][1] -                elif visited[G[pos][j][0]] != d + G[pos][j][1]: +    if ans == "No": +        break +    if len(E[i]) == 0: +        continue +    if human[i] == "0": +        human[i] = 0 +        q = deque([i]) +        while q: +            temp = q.popleft() +            for e in E[temp]: +                if human[e[0]] == "0": +                    human[e[0]] = human[temp] + e[1] +                    q.append(e[0]) +                elif human[e[0]] != human[temp] + e[1]: +    else: +        for e in E[i]: +            if human[e[0]] != human[i] + e[1]: +                ans = "No" +                break