/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int parent[200005];
long long connectSize[200005];
int tall[200005];
long long diff_weight[200005];
 
int searchRoot(int V){
    //頂点Vの親==頂点Vということは頂点Vはその木の根である。
    if(parent[V] == V){
        return V;
    }
    else{
        //一回ごとにparent[V]を更新する。辺の縮約
        //重さの累積和をとる
        int ROOT = searchRoot(parent[V]);
        diff_weight[V] += diff_weight[parent[V]];
        return parent[V] = ROOT;
    }
}
 
bool same(int X,int Y){
    if(searchRoot(X) == searchRoot(Y)) return true;
    else return false;
}

long long Weight(int x){
    searchRoot(x);
    return diff_weight[x];
}
 
void unite(int X,int Y,long long weight){
    //X,Yの高さが高い方の木の「高さ0の根」に高さが低い方の根を付ける
    int Xroot = searchRoot(X);
    int Yroot = searchRoot(Y);
    //辺の重みの差を計算する
    weight += Weight(X);
    weight -= Weight(Y);
    //同じ根を持つ木を併合することはしなくてよい
    if(Xroot == Yroot) return;
    if(tall[Xroot] > tall[Yroot]){
        parent[Yroot] = Xroot;
        connectSize[Xroot] += connectSize[Yroot];
        connectSize[Yroot] = connectSize[Yroot];
        diff_weight[Yroot] = weight;
    }
    else if(tall[Xroot] == tall[Yroot]){
        parent[Yroot] = Xroot;
        //高さが同じとき、YがXの根の下に入るのでYの深さはXより1深くなる
        tall[Yroot]++;
        connectSize[Xroot] += connectSize[Yroot];
        diff_weight[Yroot] = weight;
    }
    else {
        parent[Xroot] = Yroot;
        connectSize[Yroot] += connectSize[Xroot];
        connectSize[Xroot] = connectSize[Yroot];
        weight = -1*weight;
        diff_weight[Xroot] = weight;
    }
}

long long diff(int x,int y){
    return Weight(y)-Weight(x);
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    for(int i = 0;i<200005;i++){
        parent[i] = i;
        tall[i] = 0;
        connectSize[i] = 1;
        diff_weight[i] = 0;
    }
    for(int i = 0;i<M;i++){
        int left,right;long long D;cin >> left >> right >> D;left--;right--;
        if(!same(left,right)){
            unite(left,right,D);
        }
        else{
            if(diff(left,right) != D){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 8316