#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>P2;

#define fi first
#define se second

int ans[222222];
bool used[222222];

int Q=1e15,flag=0;

vector<P2>x[100009];

main(){

  for(int i=0;i<222222;i++)ans[i]=Q;

  int n,m;
  cin>>n>>m;
  vector<int>v;
  for(int i=0;i<m;i++)
  {
    int a,b,c;
    cin>>a>>b>>c;
    x[a].push_back(P2(P(b,c),0));
    x[b].push_back(P2(P(a,c),1));
    v.push_back(a);
    v.push_back(b);
  }
  sort(v.begin(),v.end());
  r(o,v.size()){
    if(!used[v[o]]){
      used[o]=1;
      int X=v[o];
      vector<int>V;
      ans[X]=0;
      V.push_back(X);
      while((int)V.size()){
        int p=V[0];
        V.erase(V.begin());
        r(i,x[p].size()){
          int l=p;
          int r=x[p][i].first.fi;
          int cost=x[p][i].fi.se;//cout<<l<<r<<endl;
          int C=x[p][i].se;
          if(!used[r]){//cout<<l<<' '<<r<<' '<<ans[l]<<' '<<ans[r]<<endl;
            used[r]=1;
            V.push_back(r);
          }
          if(C)swap(l,r);
          if(ans[l]==Q&&ans[r]!=Q){//cout<<l<<' '<<r<<' '<<ans[l]<<' '<<ans[r]<<endl;
            ans[l]=ans[r]-cost;
          }
          else if(ans[l]!=Q&&ans[r]==Q){//cout<<l<<' '<<r<<' '<<ans[l]<<' '<<ans[r]<<endl;
            ans[r]=ans[l]+cost;//cout<<l<<' '<<r<<' '<<ans[l]<<' '<<ans[r]<<endl;
          }
          else{//cout<<l<<' '<<r<<' '<<ans[l]<<' '<<ans[r]<<endl;
            if(ans[l]+cost!=ans[r])flag++;
          }
        }
      }
    }
  }

  if(flag)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}