// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair

class UnionFind{
public:
    V par,rank;// parent,rank
    UnionFind(int n);
    int Find(int x);
    void Unite(int x,int y);
    bool Same(int x,int y);
};
UnionFind::UnionFind(int n){
    par.resize(n);rank.resize(n);
    REP(i,n){par[i]=i;rank[i]=0;}
}
int UnionFind::Find(int x){
    
    return (par[x]==x?x:Find(par[x]));
}
void UnionFind::Unite(int x,int y){
    x=Find(x);y=Find(y);//parent
    
    if(x==y)return;//end
    if(rank[x]<rank[y])par[x]=y;
    else{
        par[y]=x;
        if(rank[x]==rank[y])rank[x]++;
    }
}
bool UnionFind::Same(int x,int y){
    return (Find(x)==Find(y));
}

int n,m;
map<int,V> point_list;
map<int,vector<pair<P,int>>> edges;

bool Solve(int inp){
  V l,r,d;
  V points = point_list[inp];
  vector<M> ed(n);
  REP(i,edges[inp].size()){
    l.pb(edges[inp][i].first.first);
    r.pb(edges[inp][i].first.second);
    d.pb(edges[inp][i].second);
    ed[l[i]][r[i]]=d[i];
    ed[r[i]][l[i]]=-d[i];
  }
  map<int,ll> ps;
  queue<pair<P,int>> que;
  // REP(i,l.size())que.push(mp(mp(l[i],r[i]),d[i]));
  que.push(mp(mp(l[0],r[0]),d[0]));
  ps[que.front().first.first]=0;
  ps[que.front().first.second]=que.front().second;
  FOREACH(xx,ed[que.front().first.first])que.push(mp(mp(que.front().first.first,xx.first),xx.second));
  FOREACH(xx,ed[que.front().first.second])que.push(mp(mp(que.front().first.second,xx.first),xx.second));
  que.pop();
  while(!que.empty()){
    int ll=que.front().first.first;
    int rr=que.front().first.second;
    int range=que.front().second;
    que.pop();
    if(ps.count(ll)&&ps.count(rr)){
      if(ps[rr]-ps[ll]!=range)return false;
    }else if(ps.count(ll)&&!ps.count(rr)){
      ps[rr]=ps[ll]+range;
      FOREACH(xx,ed[rr])que.push(mp(mp(rr,xx.first),xx.second));
    }else if(!ps.count(ll)&&ps.count(rr)){
      ps[ll]=ps[rr]-range;
      FOREACH(xx,ed[ll])que.push(mp(mp(rr,xx.first),xx.second));
    }else que.push(mp(mp(ll,rr),range));

  }

  return true;
}

int main(){
  cin>>n>>m;
  V l(m);V r(m);V d(m);
  REP(i,m)cin>>l[i]>>r[i]>>d[i];
  REP(i,m){l[i]--;r[i]--;}
  UnionFind uni(n);REP(i,m)uni.Unite(l[i],r[i]);
  REP(i,n)point_list[uni.Find(i)].pb(i);
  REP(i,m)edges[uni.Find(l[i])].pb(mp(mp(l[i],r[i]),d[i]));
  //この辺定数倍10^6ない  
  FOREACH(xx,point_list)if(edges[xx.first].size()&&!Solve(xx.first)){Yes(false);return 0;}//edgeの総和が2*10^5

  Yes(true);
  return 0;
}



Measured memory_bytes: 42988