/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

struct aaa {
    llong l, r, d;
};
 
aaa a[MXN];
 
bool cmp (aaa a, aaa b) {
    if (a.l == b.l) return (a.r < b.r);
    return (a.l < b.l);
}

llong n, m;
llong x[MXN], d[MXN];

vector <pll> g[MXN];

bool ok = 1;
bool used[MXN];

void dfs (llong v, llong dist = 0) {
    if (used[v]) {
        if (dist != d[v]) {
            ok = 0;
        }
        return ;
    }
    d[v] = dist;
    used[v] = 1;
    for (pll it : g[v]) {
        dfs (it.F, dist + it.S);
    }
}

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> n >> m;
    for (llong i = 1; i <= n; ++ i) {
        llong u, v, w;
        cin >> u >> v >> w;
        g[u].pb ({v, w});
        g[v].pb ({u, -w});
        if (v < u) {
            swap (u, v);
            w = -w;
        }
        a[i].l = u;
        a[i].r = v;
        a[i].d = w;
    }
    for (llong i = 1; i <= n; ++ i) {
        if (!used[i]) dfs (i);
    }
    for (llong i = 1; i <= n; ++ i) x[i] = -INF;
    sort (a + 1, a + m + 1, cmp);
    for (llong i = 1; i <= m; ++ i) {
        if (x[a[i].l] == -INF) {
            if (x[a[i].r] != -INF) {
                x[a[i].l] = x[a[i].r] - a[i].d;
            }
            else {
                x[a[i].l] = 0;
                x[a[i].r] = a[i].d;
            }
        }
        else if (x[a[i].r] == -INF) {
            if (x[a[i].l] != -INF) {
                x[a[i].r] = x[a[i].l] + a[i].d;
            }
            else {
                x[a[i].l] = 0;
                x[a[i].r] = a[i].d;
            }
        }
        else {
            if (x[a[i].r] - x[a[i].l] != a[i].d) {
                ok = 0;
            }
        }
    }
    cout << (ok ? "Yes" : "No");
    return 0;
}