module mod_weighted_union_find
  implicit none
  type weighted_union_find
    integer :: n = 0
    integer, allocatable :: par(:), rnk(:), cnt(:), pot(:)
  contains
    procedure :: find => find
    procedure :: weight => weight
    procedure :: same => same
    procedure :: unite => unite
    procedure :: diff => diff
    procedure :: size => size_of
  end type
  interface weighted_union_find
    module procedure :: newwuf
  end interface weighted_union_find
contains
  type(weighted_union_find) function newwuf(n) result(res)
    integer, intent(in) :: n
    integer :: i
    res%n = n
    allocate(res%par(n), res%rnk(n), res%cnt(n), res%pot(n))
    res%par = [(i, i = 1, n)]
    res%rnk = 0
    res%cnt = 1
    res%pot = 0
  end
  recursive integer function find(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    integer :: p
    if (this%par(i) == i) then
      res = i
      return
    end if
    p = find(this, this%par(i))
    this%pot(i) = this%pot(i) + this%pot(this%par(i))
    this%par(i) = p
    res = p
  end
  integer function weight(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    integer :: p
    p = find(this, i)
    res = this%pot(i)
  end
  logical function same(this, i, j) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = find(this, i) == find(this, j)
  end
  subroutine unite(this, i, j, w)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j, w
    integer :: x, y, z
    z = w + weight(this, i) - weight(this, j)
    x = find(this, i)
    y = find(this, j)
    if (x == y) return
    if (this%rnk(x) < this%rnk(y)) then
      call swap(x, y)
      z = -z
    end if
    if (this%rnk(x) == this%rnk(y)) this%rnk(x) = this%rnk(x) + 1
    this%par(y) = x
    this%pot(y) = z
  end
  integer function diff(this, i, j) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i, j
    res = weight(this, j) - weight(this, i)
  end
  integer function size_of(this, i) result(res)
    class(weighted_union_find), intent(inout) :: this
    integer, intent(in) :: i
    res = this%cnt(find(this, i))
  end
  subroutine swap(a, b)
    integer, intent(inout) :: a, b
    a = xor(a, b)
    b = xor(a, b)
    a = xor(a, b)
  end
end module mod_weighted_union_find
program people_on_a_line
  use mod_weighted_union_find
  implicit none
  integer :: n, m, l, r, d, i
  type(weighted_union_find) :: wuf
  read(*,*) n, m
  wuf = weighted_union_find(n)
  do i = 1, m
    read(*,*) l, r, d
    if (wuf%same(l, r)) then
      if (wuf%diff(l, r) /= d) then
        write(*,'(a)') 'No'
        stop
      end if
    else
      call wuf%unite(l, r, d)
    end if
  end do
  write(*,'(a)') 'Yes'
end program people_on_a_line