#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

#define int long long
#define double long double
vector<vector<int> > g;
vector<vector<double> > c;
vector<vector<int> > c1;
vector<vector<int> > c2;
vector<vector<int> > c3;
vector<vector<int> > c4;
vector<int> path;
vector<int> es;
vector<int> ds;
vector<int> dep;
vector<int> C;
vector<double> sum;
vector<int> sum1;
vector<int> sum2;
vector<int> sum3;
vector<int> sum4;
string res = "Yes";
map<int,int> pos;

int modpow(int a, int p, int MOD){
    if(p == 0) return 1;
    int t = modpow(a, p / 2, MOD);
    t = (t * t) % MOD;
    if(p & 1){
        t = (t * a) % MOD;
    }
    return t;
}
int modinv(int a, int MOD){
    return modpow(a, MOD - 2, MOD);
}

int MOD1 = 1000000007;
int MOD2 = 1000000009;
int MOD3 = 1000000021;
int MOD4 = 1000000033;

void dfs(int a, double s, int s1, int s2,int s3,int s4){
    pos[a] = sum1.size();
    //sum.push_back(s);
    sum1.push_back(s1);
    sum2.push_back(s2);
    sum3.push_back(s3);
    sum4.push_back(s4);
    C[a] = 1;
    for(int i=0;i<g[a].size();i++){
        if(C[g[a][i]] == 0){
            dfs(g[a][i], s + c[a][i]
                , s1 * c1[a][i] % MOD1, s2 * c2[a][i] % MOD2
                , s3 * c3[a][i] % MOD3, s4 * c4[a][i] % MOD4 );
        }else if(C[g[a][i]] == 1){
            
            //cerr << a << " " << g[a][i]<< " " << c[a][i] + s - sum[pos[g[a][i]]] << endl;
            //if(abs(c[a][i] + s - sum[pos[g[a][i]]]) > 1e-9){
            if( (c1[a][i] * s1 % MOD1) * modinv(sum1[pos[g[a][i]]], MOD1) % MOD1 != 1){
                res = "No";
            }
            if( (c2[a][i] * s2 % MOD2) * modinv(sum2[pos[g[a][i]]], MOD2) % MOD2 != 1){
                res = "No";
            }
            if( (c3[a][i] * s3 % MOD3) * modinv(sum3[pos[g[a][i]]], MOD3) % MOD3 != 1){
                res = "No";
            }
            if( (c4[a][i] * s4 % MOD4) * modinv(sum4[pos[g[a][i]]], MOD4) % MOD4 != 1){
                res = "No";
            }
            
            //}
        }
    }
    sum1.pop_back();
    sum2.pop_back();
    sum3.pop_back();
    sum4.pop_back();
    //sum.pop_back();
    C[a] = 2;
}
signed main(){
    //cerr << setprecision(15) << exp(1e-9)<<endl;
    //cerr << setprecision(30)<< log(1e18) - log(1e18-1)<<endl;
    int N, M;
    cin >> N >> M;
    g.resize(N);
    c.resize(N);
    c1.resize(N);
    c2.resize(N);
    c3.resize(N);
    c4.resize(N);
    dep.resize(N, 0);
    C.resize(N, 0);
    int a,b,cost;
    for(int i=0;i<M;i++){
        cin >> a >> b >> cost; a--;b--;
        g[a].push_back(b);
        c[a].push_back(log(cost));
        c1[a].push_back(cost);
        c2[a].push_back(cost);
        c3[a].push_back(cost);
        c4[a].push_back(cost);
        
        g[b].push_back(a);
        c[b].push_back(-log(cost));
        
        c1[b].push_back(modinv(cost, MOD1));
        c2[b].push_back(modinv(cost, MOD2));
        c3[b].push_back(modinv(cost, MOD3));
        c4[b].push_back(modinv(cost, MOD4));
        //cerr << cost << " " << modinv(cost, MOD1)<<endl;
    }
    
    for(int i=0;i<N;i++){
        if(C[i] == 0){
            dfs(i, 0, 1, 1, 1, 1);
        }
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 64588