// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

#define X first

#define Y second

#define pb push_back

#define sz(a) (int)a.size()



void solve();



signed main() {

#ifdef ONPC

    freopen("in.txt", "r", stdin);

#endif // ONPC

    //freopen("time.in", "r", stdin);

    //freopen("time.out", "w", stdout);

    ios_base::sync_with_stdio(0), cin.tie(0);

    int t = 1;

    //cin >> t;

    while (t--) solve();

    return 0;

}



const int N = 1e5 + 5;

int n, m, kek, dist[N];

vector<pair<int, int>> g[N], gr[N];

bool used[N];

vector<int> ord;



void dfs(int v) {

    used[v] = 1;

    for (auto d : g[v]) {

        if (!used[d.X]) {

            dfs(d.X);

        }

    }

    ord.pb(v);

}



void dfs2(int v) {

    used[v] = 1;

    for (auto d : gr[v]) {

        if (!used[d.X]) {

            dfs2(d.X);

        }

    }

    ++kek;

}



void solve() {

    cin >> n >> m;

    for (int i = 1; i <= m; ++i) {

        int l, r, d;

        cin >> l >> r >> d;

        g[l].pb({r, d});

        gr[r].pb({l, d});

    }

    for (int i = 1; i <= n; ++i) {

        if (!used[i]) {

            dfs(i);

        }

    }

    reverse(ord.begin(), ord.end());

    memset(used, 0, sizeof used);

    for (auto d : ord) {

        if (!used[d]) {

            kek = 0;

            dfs2(d);

            if (kek > 1) {

                cout << "No\n";

                return;

            }

        }

    }

    for (auto d : ord) {

        if (d == ord[0]) continue;

        dist[d] = -1;

        for (auto t : gr[d]) {

            int nw = dist[t.X] + t.Y;

            if (dist[d] != -1 && nw != dist[d]) {

                cout << "No\n";

                return;

            }

            dist[d] = dist[t.X] + t.Y;

        }

    }

    cout << "Yes\n";

}


// Faster C++ solution for the same problem (measured speedup: 1.8359404577896408x):
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<vector>

#include<set>

#include<map>

#include<unordered_set>

#include<unordered_map>

#include<queue>

#include<ctime>

#include<cassert>

#include<complex>

#include<string>

#include<cstring>

#include<chrono>

#include<random>

#include<bitset>



#define fi first

#define se second

#define mp make_pair

#define eb emplace_back

#define all(v) v.begin(), v.end()

#define sz(v) (int) v.size()



using namespace std;



mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



typedef long long lox;

typedef long double lod;

typedef unsigned long long pox;

typedef pair<int, int> pii;



const int MAX_N = 1e5 + 5;



int n, m;

vector<pii> g[MAX_N];

int x[MAX_N], deg_in[MAX_N];

bool used[MAX_N];



void dfs(int v) {

	used[v] = true;

	for (auto &e : g[v]) {

		int u = e.fi, w = e.se;

		if (!used[u]) {

			x[u] = x[v] + w;

			dfs(u);

		}

	}

}



signed main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	cin >> n >> m;

	for (int i = 1; i <= m; ++i) {

		int l, r, d;

		cin >> l >> r >> d;

		g[l].eb(r, d);

		deg_in[r]++;

	}

	for (int i = 1; i <= n; ++i) {

		if (!deg_in[i]) {

			dfs(i);

		}

	}

	for (int v = 1; v <= n; ++v) {

		for (auto &e : g[v]) {

			int u = e.fi, w = e.se;

			if (x[u] != x[v] + w) {

				cout << "No\n";

				return 0;

			}

		}

	}

	cout << "Yes\n";

	return 0;

}