CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque
def sol():
    n,m=list(map(int,input().split()))
    t,w={},{}
    p,q=set(),set()
    for i in range(m):
        l,r,d=[int(i) for i in input().split()]
        t[(l,r)]=d
        if l in w:
            w[l].add((r,d))
        else:
            w[l]={(r,d)}
        p.add(l)
        q.add(r)
    s=p-q
    #chk=set()
    chk=deque()
    if len(s)==0:
        print((["No","Yes"][m==0]))
        exit()
    for i in s:
        #chk.add((i,0))
        chk.append((i,0))
        while len(chk):
            x=chk.pop()
            if x[0] in w:
                for j in w[x[0]]:
                    if (i,j[0]) in t and t[(i,j[0])]!=x[1]+j[1]:
                    #if (x[0],j[0]) in t and t[(i,j[0])]!=
                        print("No")
                        exit()
                    elif (i,j[0]) not in t:
                        t[(i,j[0])]=x[1]+j[1]
                        #chk.add((j[0],x[1]+j[1]))
                        chk.append((j[0],x[1]+j[1]))
                    else:
                        #chk.add((j[0],x[1]+j[1]))
                        chk.append((j[0],x[1]+j[1]))
    print("Yes")

if __name__=="__main__":
    sol()


# Optimized solution
def sol():
    n,m=list(map(int,input().split()))
    t,w={},{}
    p,q=set(),set()
    for i in range(m):
        l,r,d=[int(i) for i in input().split()]
        if l in w: w[l].add((r,d))
        else: w[l]={(r,d)}
        p.add(l)
        q.add(r)
    s=p-q
    chk=set()
    if len(s)==0:
        print((["No","Yes"][m==0]))
        exit()
    for i in s:
        chk.add((i,0))
        while len(chk):
            x=chk.pop()
            if x[0] in w:
                for j in w[x[0]]:
                    if (i,j[0]) in t and t[(i,j[0])]!=t[(i,x[0])]+j[1]:
                        print("No")
                        exit()
                    elif (i,j[0]) not in t:
                        #t[(i,j[0])]=t[(i,x[0])]+j[1]
                        t[(i,j[0])]=x[1]+j[1]
                        chk.add((j[0],x[1]+j[1]))
    print("Yes")

if __name__=="__main__":
    sol()
# Original solution
N, M = list(map(int, input().split()))

LRDi = []
for _ in range(M):
    a = list(map(int, input().split()))
    LRDi.append(a)

tree = [None] * (N + 1)

def parent(n):
    if tree[n] is None:
        return [n, 0]
    d = distance_to_root(n)
    p = parent(tree[n][0])
    tree[n][0] = p[0]
    tree[n][1] = d
    return tree[n]

def distance_to_root(n):
    if tree[n] is None:
        return 0
    d = distance_to_root(tree[n][0])
    return d + tree[n][1]

for l, r, d in LRDi:
    lp = parent(l)
    rp = parent(r)
    if lp[0] != rp[0]:
        rd = distance_to_root(r)
        tree[rp[0]] = [lp[0], lp[1] + d - rd]
    else:
        d1 = distance_to_root(l)
        d2 = distance_to_root(r)
        if d1 + d != d2:
            print("No")
            exit()

print("Yes")




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

LRDi = []
for _ in range(M):
    a = list(map(int, input().split()))
    LRDi.append(a)

tree = [None] * (N + 1)

def parent(n):
    if tree[n] is None:
        return [n, 0]
    p = parent(tree[n][0])
    if p[0] == tree[n][0]:
        return tree[n]
    d = distance_to_root(n)
    tree[n][0] = p[0]
    tree[n][1] = d
    return tree[n]

def distance_to_root(n):
    ret = 0
    nn = n
    while tree[nn] is not None:
        ret += tree[nn][1]
        nn = tree[nn][0]
    return ret

for l, r, d in LRDi:
    lp = parent(l)
    rp = parent(r)
    if lp[0] != rp[0]:
        rd = distance_to_root(r)
        tree[rp[0]] = [lp[0], lp[1] + d - rd]
    else:
        d1 = distance_to_root(l)
        d2 = distance_to_root(r)
        if d1 + d != d2:
            print("No")
            exit()

print("Yes")
# Original solution
import sys
input = sys.stdin.readline


def floyd_warshall(dist):
    v = len(dist)
    for k in range(v):
        for i in range(v):
            for j in range(v):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])


N, M = list(map(int, input().split()))
G = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    G[i][i] = 0
LRD = [None] * M
for i in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    G[L][R] = D
    LRD[i] = (L, R, D)
floyd_warshall(G)
for L, R, D in LRD:
    if G[L][R] != D or G[R][L] != float('inf'):
        print('No')
        exit()
print('Yes')


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
has_parent = [False] * N
LRD = [None] * M
for i in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    G[L].append((R, D))
    G[R].append((L, -D))


def dfs(v):
    visited[v] = True
    for u, d in G[v]:
        if dist[u] == float('inf'):
            dist[u] = dist[v] + d
        elif dist[u] != dist[v] + d:
            print('No')
            exit()
        if not visited[u]:
            dfs(u)


dist = []
visited = [False] * N
for v in range(N):
    if not visited[v]:
        dist = [float('inf')] * N
        dist[v] = 0
        dfs(v)
print('Yes')
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
has_parent = [False] * N
LRD = [None] * M
for i in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    G[L].append((R, D))
    G[R].append((L, -D))


def dfs(v):
    visited[v] = True
    for u, d in G[v]:
        if dist[u] == float('inf'):
            dist[u] = dist[v] + d
        elif dist[u] != dist[v] + d:
            print('No')
            exit()
        if not visited[u]:
            dfs(u)


dist = []
visited = [False] * N
for v in range(N):
    if not visited[v]:
        dist = [float('inf')] * N
        dist[v] = 0
        dfs(v)
print('Yes')


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]
has_parent = [False] * N
for i in range(M):
    L, R, D = list(map(int, input().split()))
    L -= 1
    R -= 1
    G[L].append((R, D))
    has_parent[R] = True


def dfs(v):
    visited[v] = True
    for u, d in G[v]:
        if dist[u] == float('inf'):
            dist[u] = dist[v] + d
        if dist[u] != dist[v] + d:
            print('No')
            exit()
        dfs(u)


dist = []
visited = [False] * N
for v in range(N):
    if not has_parent[v]:
        dist = [float('inf')] * N
        dist[v] = 0
        dfs(v)
if all(visited):
    print('Yes')
else:
    print('No')
# Original solution
def main():
	N, M = list(map(int,input().split()))
	INF = 10**9+7
	if M == 0:
		print("Yes")
		return
	x = [[INF for _ in range(N)] for _ in range(N)]
	for i in range(M):
		l, r, d = list(map(int, input().split()))
		l, r = l-1, r-1
		x[l][r] = d
		x[r][l] = -d
	ans_exist = True
	for k in range(N):
		for i in range(N):
			for j in range(N):
				if x[i][j] == INF:
					continue
				x[i][j] = min(x[i][j], x[i][k]+x[k][j])

	for i in range(N):
		for j in range(N):
			if x[i][j] == x[j][i] and x[i][j] == INF:
				continue
			if x[i][j] != -x[j][i]:
				ans_exist = False
				break
	if ans_exist:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()

# Optimized solution
def main():
	N, M = list(map(int,input().split()))
	if M == 0:
		print("Yes")
		return
	x = [[] for _ in range(N)]
	ans = [0 for _ in range(N)]
	for i in range(M):
		l, r, d = list(map(int, input().split()))
		l, r = l-1, r-1
		x[l].append([r, d])
		x[r].append([l, -d])

	visited = [False for _ in range(N)]

	def dfs(i):
		vs = [i]
		while vs:
			v = vs.pop()
			for nex in x[v]:
				if not visited[nex[0]]:
					visited[nex[0]] = True
					ans[nex[0]] = ans[v]+nex[1]
					vs.append(nex[0])
				else:
					if ans[nex[0]] != ans[v]+nex[1]:
						return False
		return True

	ans_exist = True
	for i in range(N):
		if not visited[i]:
			visited[i] = True
			ans_exist = dfs(i)
		if not ans_exist:
			break

	if ans_exist:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int,input().split()))

Dlist = [[0 for i in range(N+1)] for j in range(N+1)]

L2Rdic = {i:[] for i in range(N+1)}
R2Ldic = {i:[] for i in range(N+1)}

flag=True

for _ in range(M):
    L,R,D=list(map(int,input().split()))

    if Dlist[L][R]==0:
        Dlist[L][R]=D
        L2Rdic[L].append(R)
        R2Ldic[R].append(L)
    elif Dlist[L][R]!=D:
        flag=False

    for r in L2Rdic[R]:
        if Dlist[L][r]==0:
            Dlist[L][r]=D+Dlist[R][r]
            L2Rdic[L].append(r)
            R2Ldic[r].append(L)
        elif Dlist[L][r]!=D+Dlist[R][r]:
            flag=False

    for l in R2Ldic[L]:
        if Dlist[l][R]==0:
            Dlist[l][R]=Dlist[l][L]+D
            L2Rdic[l].append(R)
            R2Ldic[R].append(l)
        elif Dlist[l][R]!=Dlist[l][L]+D:
            flag=False

    if flag==False:
        print('No')
        exit()
print('Yes')


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

L2R = {i:[] for i in range(N+1)}
R2L = {i:[] for i in range(N+1)}

for _ in range(M):
    L,R,D=list(map(int,input().split()))
    L2R[L].append((R,D,L))
    R2L[R].append((L,-D,R))

x = [0 for i in range(N+1)]
f = [True for i in range(N+1)]

for i in range(1,N+1):
    if f[i]:
        f[i]=False
        x[i]=i
        que=L2R[i]+R2L[i]
        while len(que)>0:
            tmp = []
            for end,d,begin in que:
                if f[end]:
                    f[end]=False
                    x[end]=d+x[begin]
                    tmp+=L2R[end]+R2L[end]
                elif x[end]!=d+x[begin]:
                    print('No')
                    exit()
            que=tmp
print('Yes')
# Original solution
# ABC087D
# https://atcoder.jp/contests/abc087/tasks/arc090_b

def Find(x, par, diff_weight):
    if par[x] < 0:
        return x
    else:
        px = Find(par[x], par, diff_weight)
        diff_weight[x] += diff_weight[par[x]]
        par[x] = px
        return px

def Unite(x, y, par, rank, diff_weight, w):
    w += diff_weight[x] - diff_weight[y]
    x = Find(x, par, diff_weight)
    y = Find(y, par, diff_weight)

    if x != y:
        if rank[x] < rank[y]:
            x, y =  y, x
            w = -w
        if rank[x] == rank[y]:
            rank[x] += 1
        par[x] += par[y]
        par[y] = x
        diff_weight[y] = w

def Same(x, y, par, diff_weight):
    return Find(x, par,diff_weight) == Find(y, par, diff_weight)

def Size(x, par, diff_weight):
    return -par[Find(x, par, diff_weight)]

def Weight(x, par, diff_weight):
    Find(x, par, diff_weight)
    return diff_weight[x]

def Diff(x, y, par, diff_weight):
    return Weight(y, par, diff_weight)  - Weight(x, par, diff_weight)

import sys
input = sys.stdin.readline

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

par = [-1]*n
rank = [0]*n
diff_weight = [0]*n
for i in range(m):
    l, r, d = list(map(int, input().split()))
    l, r = l-1 ,r-1
    if not Same(l, r, par, diff_weight):
        Unite(l, r, par, rank, diff_weight, d)
    else:
        if d != Diff(l, r, par, diff_weight):
            print('No')
            exit()
print('Yes')


# Optimized solution
def Find(x, par, diff_weight):
    if par[x] < 0:
        return x
    else:
        px = Find(par[x], par, diff_weight)
        diff_weight[x] += diff_weight[par[x]]
        par[x] = px
        return px

def Unite(x, y, par, rank, diff_weight, w):
    w += diff_weight[x] - diff_weight[y]
    x = Find(x, par, diff_weight)
    y = Find(y, par, diff_weight)

    if x != y:
        if rank[x] < rank[y]:
            x, y =  y, x
            w = -w
        if rank[x] == rank[y]:
            rank[x] += 1
        par[x] += par[y]
        par[y] = x
        diff_weight[y] = w

def Same(x, y, par, diff_weight):
    return Find(x, par,diff_weight) == Find(y, par, diff_weight)

def Size(x, par, diff_weight):
    return -par[Find(x, par, diff_weight)]

def Weight(x, par, diff_weight):
    Find(x, par, diff_weight)
    return diff_weight[x]

def Diff(x, y, par, diff_weight):
    return Weight(y, par, diff_weight)  - Weight(x, par, diff_weight)

import sys
input = sys.stdin.buffer.readline
n, m = list(map(int, input().split()))

par = [-1]*n
rank = [0]*n
diff_weight = [0]*n

for i in range(m):
    l, r, d = list(map(int, input().split()))
    l, r = l-1, r-1
    if not Same(l, r, par, diff_weight):
        Unite(l, r, par, rank, diff_weight, d)
    else:
        if Diff(l, r, par, diff_weight) != d:
            print('No')
            exit()
else:
    print('Yes')
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(10**7)

n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

graph = {j:[] for j in range(n)}
for i in range(m):
    l, r, d = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

yet = set(list(range(n)))
x_ls = [None for i in range(n)]
x_ls[0] = 0
que = deque([0])
flg = True
while len(que) > 0:
    cur = que.popleft()
    if cur in yet:
        yet.remove(cur)
    cur_pos = x_ls[cur]
    for _next, dis in graph[cur]:
        if x_ls[_next] is None:
            x_ls[_next] = cur_pos + dis
            que.append(_next)
        else:
            if x_ls[_next] != cur_pos + dis:
                flg = False
                break
    if not flg:
        break
    if len(que) == 0 and len(yet) > 0:
        root = list(yet)[0]
        que.append(root)
        x_ls[root] = 0
        yet.remove(root)
if flg:
    print("Yes")
else:
    print("No")

# Optimized solution
import sys
sys.setrecursionlimit(10**7)

n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

graph = {j:[] for j in range(n)}
for i in range(m):
    l, r, d = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

already = set()
x_ls = [None for i in range(n)]
x_ls[0] = 0
stack = list(range(n))[::-1]
flg = True
while len(stack) > 0:
    cur = stack.pop(-1)
    if cur in already:
        continue
    if x_ls[cur] is None:
        cur_pos = 0
    else:
        cur_pos = x_ls[cur]
    already.add(cur)
    for _next, dis in graph[cur]:
        if x_ls[_next] is None:
            x_ls[_next] = cur_pos + dis
            stack.append(_next)
        else:
            if x_ls[_next] != cur_pos + dis:
                flg = False
                break
    if not flg:
        break
if flg:
    print("Yes")
else:
    print("No")
# Original solution
import collections, sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))
graph = [[] for i in range(n + 1)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    graph[l].append([r, d])
    graph[r].append([l, -d])
flags = [False for i in range(n + 1)]
place = [0 for i in range(n + 1)]

num = 0
flag = True
while num <= n:
    if flag == False:
        break
    if flags[num] == True:
        num += 1
        continue
    if graph[num] == []:
        flags[num] = True
        num += 1
        continue
    queue = collections.deque([num])
    while queue:
        if flag == False:
            break
        test = queue.popleft()
        flags[test] = True
        for i in graph[test]:
            if flags[i[0]] == True:
                if place[i[0]] - place[test] != i[1]:
                    flag = False
                    break
            else:
                place[i[0]] = place[test] + i[1]
                queue.append(i[0])
    else:
        num += 1
if flag == True:
    print("Yes")
else:
    print("No")

# Optimized solution
import collections, sys
input = sys.stdin.readline

n, m = list(map(int, input().split()))
graph = [[] for i in range(n + 1)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    graph[l].append([r, d])
    graph[r].append([l, -d])
place = [None for i in range(n + 1)]

num = 0
flag = True
while num <= n:
    if flag == False:
        break
    if place[num] != None:
        num += 1
        continue
    place[num] = 0
    queue = collections.deque([num])
    while queue:
        if flag == False:
            break
        test = queue.popleft()
        for i in graph[test]:
            if place[i[0]] != None:
                if place[i[0]] - place[test] != i[1]:
                    flag = False
                    break
            else:
                place[i[0]] = place[test] + i[1]
                queue.append(i[0])
    else:
        num += 1
if flag == True:
    print("Yes")
else:
    print("No")
# Original solution
# 解説みたよ
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for i in range(n)]
l, r, d = [0] * m, [0] * m, [0] * m
for i in range(m):
    l[i], r[i], d[i] = list(map(int, input().split()))
    l[i] -= 1
    r[i] -= 1
    es[l[i]].append((r[i], d[i]))
    es[r[i]].append((l[i], -d[i]))
INF = 1000000000000
value = [INF] * n


def dfs(v):
    for i, d in es[v]:
        if value[i] == INF:
            value[i] = value[v] + d
            dfs(i)


for i in range(n):
    if value[i] == INF:
        value[i] = 0
        dfs(i)

for i, j, k in zip(l, r, d):
    if value[j] - value[i] != k:
        print("No")
        exit()
print("Yes")


# Optimized solution
# 解説みたよ
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
es = [[] for i in range(n)]
l, r, d = [0] * m, [0] * m, [0] * m
for i in range(m):
    l[i], r[i], d[i] = list(map(int, input().split()))
    l[i] -= 1
    r[i] -= 1
    es[l[i]].append((r[i], d[i]))
    es[r[i]].append((l[i], -d[i]))
INF = 1000000000000
value = [INF] * n


def dfs(v):
    for i, di in es[v]:
        if value[i] == INF:
            value[i] = value[v] + di
            dfs(i)


for i in range(n):
    if value[i] == INF:
        value[i] = 0
        dfs(i)

for i, j, k in zip(l, r, d):
    if value[j] - value[i] != k:
        print("No")
        exit()
print("Yes")
# Original solution
n,m=list(map(int,input().split()))
ans=[10**10]*n
edge=[[]for _ in range(n)]
for _ in range(m):
	l,r,d=list(map(int,input().split()))
	l-=1
	r-=1
	edge[l].append([r,d])
	edge[r].append([l,-d])
for i in range(n):
	if ans[i]==10**10:
		ans[i]=0
		Q=[i]
		while Q:
			P=[]
			for i in Q:
				for j,d in edge[i]:
					if ans[j]==10**10:
						P+=[j]
						ans[j]=ans[i]+d
			Q=P
for i in range(n):
	for j,k in edge[i]:
		if ans[i]+k!=ans[j]:print("No");exit()
print("Yes")

# Optimized solution
n,m=list(map(int,input().split()))
ans=[10**10]*n
edge=[[]for _ in range(n)]
for _ in range(m):
  l,r,d=list(map(int,input().split()))
  l-=1;r-=1
  edge[l].append((r,d))
  edge[r].append((l,-d))
for i in range(n):
  if ans[i]==10**10:
    ans[i]=0
    Q=[i]
    while Q:
      P=[]
      for j in Q:
        for k,d in edge[j]:
          if ans[k]==10**10:
            ans[k]=ans[j]+d
            P.append(k)
          elif ans[j]+d!=ans[k]:
            print("No");exit()
      Q=P
print("Yes")
# Original solution
class WeightsUnionfind:
  def __init__(self,n):
    self.Tree=[i for i in range(n)]
    self.dWeights=[0]*n
    self.wrong=0

  def find(self,x):
    if x==self.Tree[x]:
      return x
    else:
      root=self.find(self.Tree[x])
      self.dWeights[x]=self.weigh(x)
      self.Tree[x]=root
      return root
  
  def weigh(self,x):
    if x==self.Tree[x]:
      return 0
    else:
      w=self.weigh(self.Tree[x])+self.dWeights[x]
      return w

  def unite(self,x,y,w):
    s1=self.find(x)
    s2=self.find(y)
    if s1==s2:
      if self.weigh(y)-self.weigh(x)!=w:
        self.wrong=1
    else:
      self.Tree[s1]=s2
      self.dWeights[s1]=self.weigh(y)-self.weigh(x)-w
      
N,M=list(map(int,input().split()))
wuf=WeightsUnionfind(N)
F=0
for m in range(M):
  l,r,d=list(map(int,input().split()))
  wuf.unite(l-1,r-1,d)
if wuf.wrong==1:
  print("No")
else:
  print("Yes")
    

  
      
    
      
      

# Optimized solution
class WeightsUnionfind:
  def __init__(self,n):
    self.Tree=[i for i in range(n)]
    self.dWeights=[0]*n
    self.rank=[0]*n
    self.wrong=0

  def find(self,x):
    if x==self.Tree[x]:
      return x
    else:
      root=self.find(self.Tree[x])
      self.dWeights[x]=self.weigh(x)
      self.Tree[x]=root
      return root
  
  def weigh(self,x):
    if x==self.Tree[x]:
      return 0
    else:
      w=self.weigh(self.Tree[x])+self.dWeights[x]
      return w

  def unite(self,x,y,w):
    s1=self.find(x)
    s2=self.find(y)
    if s1==s2:
      if self.weigh(y)-self.weigh(x)!=w:
        self.wrong=1
    else:
      if self.rank[s1]>self.rank[s2]:
        self.Tree[s2]=s1
        self.dWeights[s2]=self.weigh(x)-self.weigh(y)+w
      elif self.rank[s1]<self.rank[s2]:
        self.Tree[s1]=s2
        self.dWeights[s1]=self.weigh(y)-self.weigh(x)-w
      else:
        self.Tree[s2]=s1
        self.rank[s1]+=1
        self.dWeights[s2]=self.weigh(x)-self.weigh(y)+w
          
N,M=list(map(int,input().split()))
wuf=WeightsUnionfind(N)
F=0
for m in range(M):
  l,r,d=list(map(int,input().split()))
  wuf.unite(l-1,r-1,d)
if wuf.wrong==1:
  print("No")
else:
  print("Yes")
# Original solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def dfs(u, cost):
        visited[u] = True
        for v, w in edge[u]:
            if costs.get(v) and costs[v] != cost + w:
                print("No")
                sys.exit()
            costs[v] = cost + w
            dfs(v, cost + w)

    from collections import defaultdict
    n, m = list(map(int, readline().split()))
    edge = defaultdict(list)

    for _ in range(m):
        l, r, d = list(map(int, readline().split()))
        edge[l].append((r, d))

    visited = [False] * (n + 1)

    for u in range(1, n + 1):
        costs = dict()
        if not visited[u]:
            dfs(u, 0)
    print("Yes")


if __name__ == '__main__':
    main()


# Optimized solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict, deque
    n, m = list(map(int, readline().split()))
    edge = defaultdict(list)

    for _ in range(m):
        l, r, d = list(map(int, readline().split()))
        edge[l].append((r, d))
        edge[r].append((l, -d))

    visited = [False] * (n + 1)

    for x in range(1, n + 1):
        costs = dict()
        if not visited[x]:
            costs[x] = 0
            que = deque()
            que.append((x, 0))
            while que:
                u, cost = que.popleft()
                visited[u] = True
                while edge[u]:
                    v, w = edge[u].pop()
                    if v in costs:
                        if costs[v] != cost + w:
                            print("No")
                            sys.exit()
                    costs[v] = cost + w
                    que.append((v, cost + w))

    print("Yes")


if __name__ == '__main__':
    main()