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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

#define MOD097 1000000007

///// For Debug

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// 提出時はコメントアウト
// #define LOCAL
#define DEBUG_

#ifndef LOCAL
#undef DEBUG_
#endif

#ifdef DEBUG_

#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)

#endif

//////////

struct UnionFind {
  vector< ll > data;
 
  UnionFind(ll sz) {
    data.assign(sz, -1);
  }
 
  bool unite(ll x, ll y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  ll find(ll k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  ll size(ll k) {
    return (-data[find(k)]);
  }
};



struct EV {
    ll i;
    ll v;
    bool plus;
    ll index;
};

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll N,M;
    cin >> N >> M;

    vecl L(M),R(M),D(M);

    UnionFind tree(N+10);

    map<ll,vector<EV>> G;

    rep(i,M) {
        cin >> L[i] >> R[i] >> D[i];

        tree.unite(L[i],R[i]);
        G[L[i]].push_back(EV{i,R[i],true,i});
        G[R[i]].push_back(EV{i,L[i],false,-1*i});
    }

    map<ll,vector<ll>> memo;
    map<ll,unordered_set<ll>> memo_set;
    
    unordered_set<ll> maybe;
    rep(i,M) {
        auto parent = tree.find(L[i]);
        memo[parent].push_back(i);

        if (memo_set[parent].count(L[i]) > 0 || memo_set[parent].count(R[i]) > 0) {
            maybe.insert(parent);
        }

        memo_set[parent].insert(L[i]);
        memo_set[parent].insert(R[i]);
    }
    
    for (auto &parent : maybe) {
        map<ll,ll> posit; // posit[i] = iの座標
        stack<ll> S;
        unordered_set<ll> seen_ev;

        S.push(parent);
        posit[parent] = 0;

        while (!S.empty()) {
            auto current = S.top();
            S.pop();
            
            if (G.size() == 0) continue;
            for (auto &ev : G[current]){
                if (seen_ev.count(ev.index) > 0) continue;

                ll x = current;
                ll y = ev.v;

                if (posit.count(y) == 0) {
                    S.push(ev.v);
                    seen_ev.insert(ev.index);
                }

                ll n;
                if (ev.plus) {
                    n = posit[x] + D[ev.i];
                }
                else  {
                    n = posit[x] - D[ev.i];
                }

                if (posit.count(y) > 0 && posit[y] != n)  {
                    cout << "No" << endl;
                    return 0;
                }

                posit[y] = n;
            }

        }
    }



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


Measured memory_bytes: 50544