module UnionFind_Potential

implicit none
integer,allocatable,dimension(:)::par
!parentより
integer,allocatable,dimension(:)::diff_weight

contains

recursive function root(x) result(res)
  integer :: x,res

  if(par(x) /= x)then
    par(x) = root(par(x))
    diff_weight(x)=diff_weight(x)+diff_weight(par(x))
  endif
  res = par(x)
end function

subroutine unite(x,y,w)
  !x+w=yとなるように繋げます
  integer :: x,y,w,rx,ry,rw
  !rx,ryはそれぞれの根っこ
  !rwはrxとryの差分です
  
  rx = root(x);ry = root(y)
  
  !rx + weight(x) +w=ry+weight(y)から
  rw = w + weight(x)-weight(y)
  
  if(rx /= ry)then
    par(rx) = ry
    diff_weight(ry)=rw
  endif
end subroutine

function weight(x)
  integer::x,weight
  if(root(x)==x)then
    weight=0
  else
    weight=diff_weight(x)
  endif
end function

function diff(x,y)
  integer::x,y,diff
  diff=weight(y)-weight(x)
end function
end module UnionFind_Potential

use UnionFind_Potential

integer n,m
integer l,r,d
read*,n,m
allocate(par(n),diff_weight(n))

!初期化
do i=1,n
  par(i)=i
end do
diff_weight=0

do i=1,m
  read*,l,r,d
  
  if(root(l)/=root(r))then
    call unite(l,r,d)
  else  
    if(weight(r)-weight(l)/=d)then
      print"(A)","No"
      STOP
    end if    
  endif
  
end do

print"(A)","Yes"

end