module Weighted_UF
    
    integer, allocatable, dimension(:) :: par, rank, diff_weight

    contains
    
    subroutine init(N)
        integer :: N
        allocate(par(N), rank(N), diff_weight(N))
        do i = 1, N
            par(i) = i
            rank(i) = 0
            diff_weight(i) = 0
        end do
    end subroutine

    recursive function root(x) result (res)
        integer :: x, res
        if (par(x) == x)then 
            res = x
        else
            res = root(par(x))
            diff_weight(x) = diff_weight(x) + diff_weight(par(x))
            par(x) = res
        end if
    end function

    function weight(x) result (res)
        integer :: x, res, r
        res = diff_weight(x)
        r = root(x)
    end function

    function same(x, y) result (res)
        integer :: x, y
        logical :: res
        res = (root(x) == root(y))
    end function
    
    subroutine unite(x, y, w)
        integer :: x, y, w
        w = w + weight(x) - weight(y)
        x = root(x); y = root(y)
        if (x /= y) then
            if(rank(x) < rank(y)) then
                x = xor(x, y); y = xor(y, x); x = xor(x, y) !swap
                w = -w
            end if
            if(rank(x) == rank(y)) then
                rank(x) = rank(x) + 1
            end if
            par(y) = x
            diff_weight(y) = w
        end if
    end subroutine

    function diff(x, y) result (res)
        integer :: x, y, res
        res = weight(y) - weight(x)
    end function
    
    subroutine print_UF(N)
        integer :: N
        print"(a)", parents
        do i = 1, N
            print*, "Number :", i , " " , par(i)
        end do
    end subroutine
end module Weighted_UF

program main
    use Weighted_UF

    integer N, M, l, r, d
    read*,N, M

    call init(N)

    do i = 1, M
        read*, l, r, d
        if (same(l, r)) then
            if (diff(l, r) /= d) then
                print*, l, r
                print"(a)", "No"
                stop
            end if
        else
            call unite(l, r, d)
        end if
        
    end do

    print"(a)", "Yes"
end