#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 5100000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7
vector<ll> fac(MAX), finv(MAX), inv(MAX);

struct UnionFind{
    vl p;
    vl rank;
    vl cnt;

    UnionFind(ll n){
        rank.resize(n,0);
        p.resize(n,0);
        cnt.resize(n,0);
        rep(i,n){
            p[i] = i;
            rank[i] = 0;
            cnt[i] = 1;
        }
    }

    ll find(ll x){
        if(x != p[x]) p[x] = find(p[x]);
        return p[x];
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] > rank[y]){
            p[y] = x;
            cnt[x] += cnt[y];
        }else{
            p[x] = y;
            cnt[y] += cnt[x];
            if(rank[x] == rank[y]) rank[y]++;
        }
    }

    ll size(ll x){
        return cnt[find(x)];
    }
};

int main(){
    ll n,m; cin >> n >> m;
    vector<vpl> G(n);
    vl indeg(n,0);
    UnionFind uf(n);
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c; a--; b--;
        indeg[b]++;
        G[a].emplace_back(b,c);
        uf.unite(a,b);
    }
    vvl groups(n);
    rep(i,n){
        if(uf.size(i)==1) continue;
        groups[uf.find(i)].push_back(i);
    }
    rep(i,n){
        if(groups[i].empty()) continue;
        ll start = -1;
        for(auto j : groups[i]){
            if(indeg[j]==0){
                start = j;
                break;
            }
        }
        if(start==-1){
            puts("No");
            return 0;
        }
        ll siz = groups[i].size();
        vl d(siz,inf);
        map<ll,ll> mp;
        rep(j,siz) mp[groups[i][j]] = j;
        d[mp[start]] = 0;
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.emplace(0,start);
        while(!pq.empty()){
            P p = pq.top(); pq.pop();
            ll u = p.second;
            for(auto v : G[u]){
                ll t = mp[v.first];
                if(d[t] != inf){
                    if(d[t] != d[mp[u]] + v.second){
                        puts("No");
                        return 0;
                    }
                }else{
                    d[t] = d[mp[u]] + v.second;
                    pq.emplace(d[t],v.first);
                }
            }
        }
    }
    puts("Yes");
}


Measured memory_bytes: 142704