#![allow(unused_macros)]
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::max($x, max!($($y),+)));
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::min($x, min!($($y),+)));
}

// solution
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
fn main() {
    input! {
        N: usize,
        M: usize,
        pos: [(usize1, usize1, isize); M],
    }

    let mut union_find = UnionFind::new(N);
    for &(l, r, d) in pos.iter() {
        if let Some(dd) = union_find.diff(l, r) {
            if dd != d {
                println!("No");
                return
            }
        } else {
            union_find.union(l, r, d);
        }
    }
    println!("Yes");
}

#[derive(Debug)]
struct UnionFind {
    node_size: usize,
    parent: Vec<usize>,
    diff_weight: Vec<isize>,
}

impl UnionFind {
    fn new(node_size: usize) -> UnionFind 
    {
        let parent = (0..node_size).collect::<Vec<usize>>();
        let diff_weight = vec![0_isize; node_size];

        UnionFind { 
            node_size: node_size, 
            parent: parent, 
            diff_weight: diff_weight }
    }

    fn root(&mut self, x: usize) -> usize
    {
        if x == self.parent[x] {
            return x
        }

        let ind = self.parent[x];
        let r = self.root(ind);
        self.diff_weight[x] += self.diff_weight[self.parent[x]];
        self.parent[x] = r;
        r
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool 
    {
        self.root(x) == self.root(y)
    }

    fn diff(&mut self, x: usize, y: usize) -> Option<isize> 
    {
        if self.is_same(x, y) {
            let d = &self.diff_weight;
            Some(d[y] - d[x])
        } else {
            None
        }
    }

    fn union(&mut self, x: usize, y: usize, w: isize) 
    {
        let w = w + self.diff_weight[x] - self.diff_weight[y];
        if self.is_same(x, y) {
            return
        }
        let x = self.root(x);
        let y = self.root(y);
        self.parent[y] = x;
        self.diff_weight[y] = w;
    }
}


Measured memory_bytes: 12668