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

#define int long long

#define x first

#define y second





using namespace std;



vector<int> color(1e5 + 1);



int get_color(int x){

    //cout << x << endl;

    if(x == color[x]){

        return x;

    }

    return color[x] =  get_color(color[x]);

}



void update(int x, int y){

    if(get_color(x) != get_color(y)){

        //cout << x << ' ' << y << endl;

        color[get_color(x)] = get_color(y);

    }

}



bool comp(vector<int> x, vector<int> y){

    return min(x[0], x[1]) < min(y[0], y[1]);

}



void check(vector<int> sv, vector<vector<int> > og){

    int n = sv.size();

    int mi = 0, ma = 0;

    if(og.size() == 0){

        return;

    }

    map<int, int> c;

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

        c[sv[i]] =i;

    }

    vector<int> used(n,  0), x(n, 0);

    used[0] = 1;

    vector<vector<vector<int> > > dop(n);

    for(auto it : og){

        dop[c[it[0]]].push_back(it);

        dop[c[it[1]]].push_back(it);

    }

    queue<vector<int> > d;

    for(auto it : dop[0]){

        d.push(it);

    }

    while(!d.empty()){

        auto it = d.front();

        d.pop();

        int t = c[it[0]], t1 = c[it[1]];

        if(used[t] == 0){

            swap(t, t1);

            it[2] = -it[2];

        }

        if(used[t1] == 0){

            for(auto it1 : dop[t1]){

                if(it1 != it)

                d.push(it1);

            }

        }

        if(used[t1] == 1 && x[t1] != x[t] + it[2]){

            cout << "No";

            exit(0);

        }

        if(used[t] == 0){

            exit(-1);

        }

        used[t1] = 1;

        x[t1] = x[t] + it[2];

    }

    for(auto it : x){

        mi = min(it, mi);

        ma = max(it, ma);

    }

    if(ma - mi > 1e9){

        cout << "No";

        exit(0);

    }

}



void solve(){

    int n, q;

    cin >> n >> q;

    vector<vector<int> > e(q);

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

        color[i] = i;

    }

    for(int i = 0 ; i < q; i++){

        int l, r, d;

        cin >> l >> r >> d;

        e[i] = {--l, --r, d};

        update(l, r);

        //cout << color[0] << ' ' << color[1] <<' ' << color[2] << endl;

    }

    vector<vector<int> > sv(n);

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

        sv[get_color(i)].push_back(i);

    }

   vector<vector<vector<int> > > og(n);

   for(auto it : e){

        og[get_color(it[0])].push_back(it);

   }

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

    sort(og[i].begin(), og[i].end(), comp);

    //out << "rhgingk" <<  endl;

    check(sv[i], og[i]);

   }

   cout << "Yes";

}





signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int test = 1;

    //freopen("output.txt", "w", stdout);

    //freopen("input.txt", "r", stdin);

    //

    //cin >> test;

    while(test--){

        solve();

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.8052957160106728x):
#include <bits/stdc++.h>

#include <unordered_map>

#include <unordered_set>

using namespace std;

#define int long long

#define eb emplace_back

#define ef emplace_front

#define rep(i, x, n) for (int i = x; i < n; ++i)

#define mp make_pair

#define fi first

#define se second

#define ii pair<int, int>

#define endl '\n'

#define vi vector<int>

#define vii vector<pair<int, int>>

#define reverse(s) reverse(s.begin(), s.end())

#define ld long double

#define vs vector<string>

#define inf INT_MAX

#define vc vector<char>

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define vb vector<bool>

#define lb(a, x) lower_bound(a.begin(), a.end(), x)

#define ub(a, x) upper_bound(a.begin(), a.end(), x) 

#define vvi vector<vi>

#define mine(a) min_element(a.begin(),a.end())

#define maxe(a) max_element(a.begin(), a.end())

#define iota(a,i) iota(a.begin(),a.end(),i)

#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}

int n, m;

map<ii, int> a;

vi par, val;

vvi adj;

vb d;

int findset(int x) {

	int u = x;

	while (par[x] != -1) {

		x = par[x];

		par[u] = x;

	}

	return x;

}

bool sameset(int x, int y) {

	return findset(x) == findset(y);

}

void unionset(int x, int y) {

	x = findset(x);

	y = findset(y);

	if (x == y) return;

	par[x] = y;

}

void dfs(int x) {

	for (int i : adj[x]) {

		if (d[i] == 0) {

			d[i] = 1;

			val[i] = val[x] + a[mp(x, i)];

			dfs(i);

		}

		else if (val[i] != val[x] + a[mp(x, i)]) {

			cout << "No";

			exit(0);

		}

	}

}

signed main() {

	fastio;

	cin >> n >> m;

	par.resize(n + 1, -1);

	adj.resize(n + 1);

	d.resize(n + 1, 0);

	val.resize(n + 1, 0);

	while (m--) {

		int x, y, z;

		cin >> x >> y >> z;

		a[mp(x, y)] = z;

		a[mp(y, x)] = -z;

		unionset(x, y);

		adj[x].emplace_back(y);

		adj[y].emplace_back(x);

	}

	rep(i, 1, n + 1) {

		if (d[i] == 0) {

			int x = findset(i);

			d[x] = 1;

			val[x] = 0;

			dfs(x);

		}

	}

	cout << "Yes";

	return 0;

}