#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;

vvii g;
int n;

bool hascycle;
vi color;

void cycle(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            cycle(u.second);
        else if(color[u.second] == 1)
            hascycle = true;
    color[v] = 2;
}

vi sorted;

void toposort(int v)
{
    color[v] = 1;
    for(ii u : g[v])
        if(!color[u.second])
            toposort(u.second);
    sorted.push_back(v);
}

bool posible;
vi dis;

void check(int v, int d)
{ 
    color[v] = 1;
    dis[v] = d;
    for(ii u : g[v])
        if(!color[u.second])
            check(u.second, d + u.first);
        else if(dis[u.second] != d + u.first)
            posible = false; 
    color[v] = 2;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int m,x,y,w;
    while(cin >> n >> m)
    {
        g = vvii(n);
        for(int i = 0; i < m; i++)
        {
            cin >> x >> y >> w; x--; y--;
            g[x].push_back({w, y});
        }
        // Cycle check
        color = vi(n, 0); hascycle = false;
        for(int i = 0; i < n; i++)
            if(!color[i])
                cycle(i);
        if(hascycle)
            cout << "No" << '\n';
        else
        {
            // Toposort
            color = vi(n, 0); sorted.clear(); 
            for(int i = 0; i < n; i++)
                if(!color[i])
                    toposort(i);
            reverse(sorted.begin(), sorted.end());
            // Distance check
            color = vi(n, 0); dis = vi(n, 0); posible = true;
            for(int v : sorted[i])
                if(!color[v])
                    check(v, 0);
            cout << (posible? "Yes" : "No") << '\n';
        }
    }
    return 0;
} 