#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


//頂点数v、辺の数e
int v, e;
    
//グラフの隣接リスト
set<pair<int,int>> g[100010];

//頂点の入次数を管理
int h[100010];

//入次数が0の頂点の集合
stack<pair<int,int>> st;

//ソートされた後のグラフ
vector<pair<int,int>> ans;
map<int,int> cost;
   
bool tsort(){
    //入次数が0の頂点であればstに追加
    rep(i,1,v+1) if(h[i] == 0) st.push(make_pair(i,0));
    
    //stがなくなるまでループ
    while(st.size()) {

        //stの集合のから一つ取り出す
        int i = st.top().ft, c = st.top().sd; 
        st.pop();

        if(cost[i] == 0){
            ans.push_back(make_pair(i,c));
            cost[i] = c;
        }else{
            if(cost[i] != c)ret false;
            else continue;
        }
        
        for(auto& j: g[i]) {

            //隣接する頂点の入次数をマイナス1
            h[j.sd]--;

            //これによって入次数が0になればstに追加
            //if(h[j.sd] <= 0)
            st.push(make_pair(j.sd, c-j.ft));
        }
    }

    ret (sz(cost)==v)?true:false;
}

void add(int s,int t,int c){

    //頂点sから頂点tへの有向辺
    g[s].it(make_pair(c,t));
    h[t]++;
}

int main(void){

    cin >> v >> e;

    rep(i,0,e) {
        int s,t,c;
        cin >> s >> t >> c;

        add(s,t,-c);
    }

    if(tsort()){
        //ansを順に出力
        //for(auto i: ans) cout << i.ft << " " << i.sd << endl;
        Yes;
    }else{
        No;
    }
    return 0;
}


Measured memory_bytes: 20212