#include <iostream>
#include <ostream>
#include <fstream>
#include <set>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define It(q) for (auto elem :(q))
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define read(vec, n) for(int (i)=0;(i)<(int)(n);++(i)) cin >> vec[i];
#define print(q) for(auto it = (q).begin(); it != (q).end();++(it)) cout << *it << ' '; cout << endl;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
/*
const int k = 26;

struct nod{
    nod* to[k] ={nullptr}, *go[k]={nullptr};
    nod* link = nullptr;
    nod* p;
    nod* up = nullptr;
    bool leaf;
    int pch;
    nod(int _pch, nod* p): pch(_pch),p(p), leaf(false) {}
};

nod* root = new nod(-1,0);

nod* go(nod* v, int c);

nod* link(nod* v){
    if (!v->link){
        if (v==root || v->p==root) v->link = root;
        else v->link = go(link(v->p),v->pch);
    }
    return v->link;
}

nod* go(nod* v, int c) {
    if (!v->go[c]){
        if (v->to[c]) v->go[c] = v->to[c];
        else if (v == root) v->go[c] = root;
        else v->go[c] = go(link(v), c);
    }
    return v->go[c];
}

nod* up(nod* v) {
    if (!v->up) {
        if (link(v)->leaf)
            v->up = link(v);
        else if (link(v) == root)
            v->up = root;
        else
            v->up = up(link(v));
    }
    return v->up;
}

void add_string(string& s) {
    nod* v = root;
    for (auto ch:s){
        int c = ch - 'a';
        if (!v->to[c]) v->to[c] = new nod(c, v);
        v = v->to[c];
    }
    v->leaf = true;
}

int main() {
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        add_string(s);
    }

    string s;
    cin>>s;
    auto now = root;
    auto temp = now;
    for (auto c:s){
        now = go(now,c-'a');
        temp = now;
        while (up(temp) != root) {
            temp = up(temp);
            cout << "YEA" << ' ' << c << endl;
        }
        if (now->leaf) {
            cout << "YEA" << ' '  << c << endl;
        }
    }
    return 0;
}*/
/*
const int p = 31;
vector<ll> has;
vector<ll> p_s;
string s;

void count_p(){
    p_s.PB(1LL);
    p_s.PB(p);
    for (int i = 2; i <= s.length(); i++)
        p_s.PB(p_s.back() * p);
}

void count_hash() {
    has.resize(2*s.length());
    for (int i = 0; i < 2*s.length(); i++) {
        int ind = i;
        if (ind >= s.size())
            ind -=s.size();
        has[ind] = (s[ind]-'a'+1)*p_s[ind];
        if (i) has[ind] += has[ind-1];
    }
}

pii hsh(int st, int siz) {
    return MP(has[st+siz-1]-(st ? has[st-1] : 0), st);
}

int lcp(int j1, int j2) {
    int l = 0, r = s.size() + 1;
    while (l < r - 1) {
        int mid = (r+l)/2;
        auto t1=hsh(j1,mid),t2=hsh(j2,mid);
        if (t1.second < t2.second) t1.first *= p_s[t2.second-t1.second];
        else t2.first *= p_s[t1.second-t2.second];
        if (t1.first == t2.first)
            l = mid;
        else
            r = mid;
    }
    return l;
}

bool comp(int j1, int j2) {
    int temp = lcp(j1,j2);
    return (temp != s.size() && s[(j1+temp)%s.size()] < s[(j2+temp)%s.size()]);
}

int main(){
    cin >> s;
    s+='0';
    vi arr(s.size());
    rep(i,s.size())
        arr[i] = i;
    count_p();count_hash();
    sort(all(arr),comp);
    reu(i,1,arr.size())
        cout<<arr[i]+1<<' ';
}*/

vector<vpii> g;
vector<bool> used;
vector<int> weig;

bool dfs(int v, int weight, int p = -1) {
    used[v] = true;
    bool found = false;
    for (auto el:g[v]) {
        int to = el.first, w = el.second;
        if (used[to] && weig[v] - weig[to] + w != 0)
            found = true;
        if (!used[to]) {
            weig[to] = weig[v] + w;
            found = dfs(to, weight + w);
        }
        if (found) break;
    }
    return found;
}

int main() {
    int n,m;
    cin>>n>>m;
    g.resize(n);
    rep(i,m) {
        int d;
        int u,v;
        cin>>u>>v>>d;
        u--,v--;
        g[u].PB(MP(v,d));
        g[v].PB(MP(u,-d));
    }
    used.assign(n, false);
    weig.assign(n,0);
    bool contradiction = false;
    for (int i = 0; i < n; i++){
        if (!used[i])
            contradiction = dfs(i, 0);
        if (contradiction) {
            break;
        }
    }
    if (!contradiction) {
        cout << "Yes";
    } else
        cout << "No";
}

Measured memory_bytes: 12032