#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;

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 T> void drop(T x){cout<<x<<endl;exit(0);};

template<typename T, T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD; if(v<0) v += MOD;}

  Mint pow(long long k){
    Mint res(1), tmp(v);
    while(k){
      if(k&1)  res *= tmp;
      tmp *= tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD- 2);}

  Mint& operator+=(Mint a){v += a.v; if(v>=MOD) v -= MOD; return *this;}
  Mint& operator-=(Mint a){v += MOD - a.v; if(v>=MOD) v-=MOD; return *this;}
  Mint& operator*=(Mint a){v = 1LL * v * a.v%MOD; return *this;}
  Mint& operator/=(Mint a){return (*this) *= a.inv();}

  Mint operator+(Mint a)const{return Mint(v)+=a;}
  Mint operator-(Mint a)const{return Mint(v)-=a;}
  Mint operator*(Mint a)const{return Mint(v)*=a;}
  Mint operator/(Mint a)const{return Mint(v)/=a;}

  Mint operator-()const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v == a.v;}
  bool operator!=(const Mint a)const{return v != a.v;}
  bool operator <(const Mint a)const{return v < a.v;}
};

template<typename T, T MOD> constexpr T Mint<T, MOD>:: mod;
template<typename T, T MOD>
ostream& operator<<(ostream &os, Mint<T, MOD> m){os<<m.v;return os;}

const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const int MOD3 = 1e9+21;
const int MOD4 = 1e9+33;
const int MOD5 = 1012924417;

using M1 = Mint<int, MOD1>;
using M2 = Mint<int, MOD2>;
using M3 = Mint<int, MOD3>;
using M4 = Mint<int, MOD4>;
using M5 = Mint<int, MOD5>;

const int MAX = 1e5+100;
int used[MAX]={};
M1 dp1[MAX]={};
M2 dp2[MAX]={};
M3 dp3[MAX]={};
M4 dp4[MAX]={};
M5 dp5[MAX]={};

int n,m;

using P = pair<int, int>;
vector<P> G[MAX],R[MAX];

template<typename T> void check(T x,T y){if(x!=y) drop("No");};

void dfs(int v){
  //cout<<v<<endl;

  for(auto e:G[v]){
    int u=e.first,x=e.second;
    if(used[u]) continue;
    used[u]=1;
    dp1[u]=dp1[v]*M1(x);
    dp2[u]=dp2[v]*M2(x);
    dp3[u]=dp3[v]*M3(x);
    dp4[u]=dp4[v]*M4(x);
    dp5[u]=dp5[v]*M5(x);
    dfs(u);
  }
  for(auto e:R[v]){
    int u=e.first,x=e.second;
    if(used[u]) continue;
    used[u]=1;
    dp1[u]=dp1[v]*M1(x).inv();
    dp2[u]=dp2[v]*M2(x).inv();
    dp3[u]=dp3[v]*M3(x).inv();
    dp4[u]=dp4[v]*M4(x).inv();
    dp5[u]=dp5[v]*M5(x).inv();
    dfs(u);
  }

  for(auto e:G[v]){
    int u=e.first,x=e.second;
    check(dp1[u],dp1[v]*M1(x));
    check(dp2[u],dp2[v]*M2(x));
    check(dp3[u],dp3[v]*M3(x));
    check(dp4[u],dp4[v]*M4(x));
    check(dp5[u],dp5[v]*M5(x));
  }
  for(auto e:R[v]){
    int u=e.first,x=e.second;
    check(dp1[u],dp1[v]*M1(x).inv());
    check(dp2[u],dp2[v]*M2(x).inv());
    check(dp3[u],dp3[v]*M3(x).inv());
    check(dp4[u],dp4[v]*M4(x).inv());
    check(dp5[u],dp5[v]*M5(x).inv());
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b,x;
    cin>>a>>b>>x;
    a--;b--;
    G[a].emplace_back(b,x);
    R[b].emplace_back(a,x);
  }

  for(int i=0;i<n;i++){
    if(used[i]) continue;
    dp1[i]=M1(1);
    dp2[i]=M2(1);
    dp3[i]=M3(1);
    dp4[i]=M4(1);
    dp5[i]=M5(1);
    dfs(i);
  }

  cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 25816