Scanf.scanf "%d %d" (fun n m ->
    let par = Array.init n (fun n -> n) in
    let rec root x =
        if par.(x) = x then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in
    let merge a b =
        if root a <> root b then par.(par.(b)) <- par.(a)
    in
    let rel = Array.make n [] in
    let pos = Array.make n 0 in
    let visited = Array.make n false in

    for i = 1 to m do
        Scanf.scanf " %d %d %d" (fun l r d ->
            let l = l - 1 in
            let r = r - 1 in
            rel.(l) <- (r, -d) :: rel.(l);
            rel.(r) <- (l,  d) :: rel.(r);
            merge l r
        )
    done;

    let rec loop i =
        if i = n then "Yes" else (
            if root i <> i then loop (i + 1) else (
                let rec dfs k expectpos =
                    if visited.(k) then (
                        pos.(k) = expectpos 
                    ) else (
                        let () = pos.(k) <- expectpos in
                        let () = visited.(k) <- true in
                        let rec loop2 = function
                            | [] -> true
                            | (p, d) :: tl ->
                                    if dfs p (d + expectpos) then loop2 tl
                                    else false
                        in
                        loop2 rel.(k)
                    )
                in
                if dfs i 0 then loop (i + 1) else "No"
            )
        )
    in
    loop 0 |> print_endline
)