#include <bits/stdc++.h>
#define N 100'000
using namespace std;
int n, m;
struct edge { int u, v, w; };
vector<edge> edges;
vector<edge> adj[N+1];
int p[N+1];
void init() {
    for(int u = 0; u <= N; u++) {
        p[u] = u;
    }
}
int find(int u) {
    return p[u] == u ? u : p[u] = find(u);
}
void merge(int u, int v) {
    p[find(u)] = find(v);
}
int indeg[N+1];
bool vis[N+1];
void toposort() {
    queue<int> bfs;
    for(int i = 1; i <= n; i++) {
        if(indeg[i] == 0) {
            bfs.push(i);
        }
    }
    while(!bfs.empty()) {
        int u = bfs.front();
        vis[u] = true;
        bfs.pop();
        for(edge e : adj[u]) {
            if(--indeg[e.v] == 0) {
                bfs.push(e.v);
            }
        }
    }
}
int d[N+1];
bool bfs_consistent(int s) {
    queue<int> bfs;
    bfs.push(s);
    d[s] = 0;
    vis[s] = true;
    bool ans = true;
    while(!bfs.empty()) {
        int u = bfs.front(); bfs.pop();
        for(edge e : adj[u]) {
            if(!vis[e.v]) {
                d[e.v] = d[u] + e.w;
                bfs.push(e.v);
                vis[e.v] = true;
            } else {
                ans &= d[e.v] == d[u] + e.w;
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    init();
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        if(w == 0) {
            merge(u, v);
        } else {
            edges.push_back({u, v, w});
        }
    }
    memset(indeg, 0, sizeof indeg);
    for(edge e : edges) {
        int u = find(e.u);
        int v = find(e.v);
        adj[u].push_back({u, v, e.w});
        indeg[v]++;
    }
    memset(vis, false, sizeof vis);
    toposort();
    bool can = true;
    for(int i = 1; i <= n && can; i++) {
        can &= vis[i];
    }
    for(edge e : edges) {
        int u = find(e.u);
        int v = find(e.v);
        adj[v].push_back({v, u, -e.w});
    }
    memset(vis, false, sizeof vis);
    for(int i = 1; i <= n && can; i++) {
        if(!vis[i]) {
            can &= bfs_consistent(i);
        }
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}