#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<(usize, usize)>>;

fn topological_sort(graph: &Graph) -> Vec<usize> {
    let mut count = vec![0; graph.len()];

    for edge in graph {
        for &(to, _) in edge {
            count[to] += 1;
        }
    }
    let mut res = vec![];
    let mut check = vec![];

    for (i, &c) in count.iter().enumerate() {
        if c == 0 {
            check.push(i);
        }
    }

    while !check.is_empty() {
        let i = check.pop().unwrap();
        for &(to, _) in &graph[i] {
            count[to] -= 1;
            if count[to] == 0 {
                check.push(to);
            }
        }
        res.push(i);
    }
    if res.len() != graph.len() {
        vec![]
    } else {
        res
    }
}

fn dfs(p: usize, graph: &Graph, depth: &mut Vec<Option<usize>>) -> bool {
    if depth[p].is_some() {
        return true;
    }
    depth[p] = Some(0);
    if graph[p].len() == 0 {
        depth[p] = Some(0);
        return true;
    }
    for i in 0..graph[p].len() {
        let next = graph[p][i].0;
        let weight = graph[p][i].1;
        let r = dfs(next, graph, depth);
        if !r {
            depth[p] = Some(0);
            return false;
        }
        if depth[p].unwrap() == 0 {
            depth[p] = Some(depth[next].unwrap() + weight);
        } else if depth[p].unwrap() != depth[next].unwrap() + weight {
            return false;
        }
    }
    true
}

fn main() {
    input! {
        n: usize,
        m: usize,
        edges: [(usize1, usize1, usize); m],
    }

    let mut graph = vec![vec![]; n];
    for &(l, r, w) in &edges {
        graph[r].push((l, w));
    }

    let rv = topological_sort(&graph);
    if rv.len() == 0 {
        println!("No");
        return;
    }

    let mut depth = vec![None; n];

    for i in 0..n {
        if depth[i].is_none() {
            if !dfs(i, &graph, &mut depth) {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 29180