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

G=[[] for i in range(n)]

for i in range(m):

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

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

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



dist=[None]*n

from collections import deque

for i in range(n):

  q=deque()

  if dist[i]==None:

    dist[i]=0

    q.append(i)

  while q:

    cur=q.popleft()

    for nx,nxd in G[cur]:

      if dist[nx]==None:

        dist[nx]=dist[cur]+nxd

        q.append(nx)

      elif dist[nx]!=dist[cur]+nxd:

        print("No")

        exit(0)

print("Yes")



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

lrd=[tuple(map(int,input().split())) for i in range(m)]



class WeightedUnionFind:

  def __init__(self,n):

    self.parent = [i for i in range(n)]

    self.rank = [0] * n

    self.count = 0

    self.weight = [0] * n

  def root(self,a):

    if self.parent[a] == a:

      return a

    else:

      pa = self.root(self.parent[a])

      self.weight[a] += self.weight[self.parent[a]]

      self.parent[a] = pa

      return pa

  def is_same(self,a,b):

    return self.root(a) == self.root(b)

  def unite(self,a,b,w):

    ra = self.root(a)

    rb = self.root(b)

    if ra == rb: return

    if self.rank[ra] < self.rank[rb]:

      self.parent[ra] = rb

      self.weight[ra] = w - self.weight[a] + self.weight[b]

    else:

      self.parent[rb] = ra

      self.weight[rb] = -w - self.weight[b] + self.weight[a]

      if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1

    self.count += 1

  def diff(self,a,b):

    return self.weight[a] - self.weight[b]



uf=WeightedUnionFind(n)

for l,r,d in lrd:

  l,r=l-1,r-1

  if uf.is_same(l,r):

    if uf.diff(l,r)!=d:

      print('No')

      exit(0)

  else:

      uf.unite(l,r,d)

print('Yes')

n, m = list(map(int, input().split()))
G = [[] for i in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))
    G[l - 1].append([r - 1, d])
    G[r - 1].append([l - 1, -d])
dist = [None] * n
from collections import deque

for i in range(n):
    q = deque()
    if dist[i] == None:
        dist[i] = 0
        q.append(i)
    while q:
        cur = q.popleft()
        for nx, nxd in G[cur]:
            if dist[nx] == None:
                dist[nx] = dist[cur] + nxd
                q.append(nx)
            elif dist[nx] != dist[cur] + nxd:
                print("No")
                exit(0)
print("Yes")

n, m = list(map(int, input().split()))
lrd = [tuple(map(int, input().split())) for i in range(m)]


class WeightedUnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
        self.count = 0
        self.weight = [0] * n

    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            pa = self.root(self.parent[a])
            self.weight[a] += self.weight[self.parent[a]]
            self.parent[a] = pa
            return pa

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def unite(self, a, b, w):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
            self.weight[ra] = w - self.weight[a] + self.weight[b]
        else:
            self.parent[rb] = ra
            self.weight[rb] = -w - self.weight[b] + self.weight[a]
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
        self.count += 1

    def diff(self, a, b):
        return self.weight[a] - self.weight[b]


uf = WeightedUnionFind(n)
for l, r, d in lrd:
    l, r = l - 1, r - 1
    if uf.is_same(l, r):
        if uf.diff(l, r) != d:
            print("No")
            exit(0)
    else:
        uf.unite(l, r, d)
print("Yes")

-G = [[] for i in range(n)] -for i in range(m): -    l, r, d = list(map(int, input().split())) -    G[l - 1].append([r - 1, d]) -    G[r - 1].append([l - 1, -d]) -dist = [None] * n -from collections import deque +lrd = [tuple(map(int, input().split())) for i in range(m)] -for i in range(n): -    q = deque() -    if dist[i] == None: -        dist[i] = 0 -        q.append(i) -    while q: -        cur = q.popleft() -        for nx, nxd in G[cur]: -            if dist[nx] == None: -                dist[nx] = dist[cur] + nxd -                q.append(nx) -            elif dist[nx] != dist[cur] + nxd: -                print("No") -                exit(0) + +class WeightedUnionFind: +    def __init__(self, n): +        self.parent = [i for i in range(n)] +        self.rank = [0] * n +        self.count = 0 +        self.weight = [0] * n + +    def root(self, a): +        if self.parent[a] == a: +            return a +        else: +            pa = self.root(self.parent[a]) +            self.weight[a] += self.weight[self.parent[a]] +            self.parent[a] = pa +            return pa + +    def is_same(self, a, b): +        return self.root(a) == self.root(b) + +    def unite(self, a, b, w): +        ra = self.root(a) +        rb = self.root(b) +        if ra == rb: +            return +        if self.rank[ra] < self.rank[rb]: +            self.parent[ra] = rb +            self.weight[ra] = w - self.weight[a] + self.weight[b] +        else: +            self.parent[rb] = ra +            self.weight[rb] = -w - self.weight[b] + self.weight[a] +            if self.rank[ra] == self.rank[rb]: +                self.rank[ra] += 1 +        self.count += 1 + +    def diff(self, a, b): +        return self.weight[a] - self.weight[b] + + +uf = WeightedUnionFind(n) +for l, r, d in lrd: +    l, r = l - 1, r - 1 +    if uf.is_same(l, r): +        if uf.diff(l, r) != d: +            print("No") +            exit(0) +    else: +        uf.unite(l, r, d)