#include <cstring>
#include <iostream>
#include <vector>

using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
const int mod = 39999931;

int n, m;
struct edge {
    int to; LL len;
    edge(int y, LL l) : to(y), len(l) { }
};
vector<edge> G[N];

LL fastpow(LL a, LL b, LL c) {
    LL r = 1;
    for (; b; b >>= 1, (a *= a) %= c)
        if (b & 1) (r *= a) %= c;
    return r;
}
LL inverse(LL a) {
    return fastpow(a, mod - 2, mod);
}

bool book[N];
LL val[N];
void solve(int x, int f) {
    book[x] = true;
    for (auto e : G[x]) {
        int y = e.to; LL l = e.len;
        if (y == f) continue;

        if (book[y]) {
            if (val[y] != val[x] * l % mod) {
                cout << "No" << endl;
                exit(0);
            }
        } else {
            val[y] = val[x] * l % mod;
            solve(y, x);
        }
    }    
}

signed main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v; LL w;
        cin >> u >> v >> w;
        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, inverse(w)});
    }
    
    for (int i = 1; i <= n; i++)
        if (!book[i]) val[i] = 1, solve(i, 0);

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