#include <bits/stdc++.h>
using namespace std;
static const long long llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const long long llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const long long d_5 = 100000;
static const long long d9_7 = 1000000007;
static const long long d_9 = 1000000000;
static const double PI = 3.14159265358979323846;
template <class T>
void Printvector(std::vector<T> a) {
  int size = a.size();
  for (int i = 0; i < size; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T>
void Printvector(std::vector<std::vector<T>> a) {
  int size = a.size();
  for (int i = 0; i < size; i++) {
    int size2 = a[i].size();
    for (int j = 0; j < size2; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
set<long long> divisor(long long n) {
  set<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.insert(i);
      if (i * i != n) ret.insert(n / i);
    }
  }
  return (ret);
}
template <class T>
T digitpower(T a, T b) {
  int mode = 1;
  if (b == 1) {
    return a;
  } else if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    T tmp = digitpower(a, (b - 1) / 2);
    if (mode == 0) {
      tmp %= d9_7;
    }
    tmp *= tmp;
    if (mode == 0) {
      tmp %= d9_7;
    }
    tmp *= a;
    if (mode == 0) {
      return (tmp) % d9_7;
    } else {
      return tmp;
    }
  } else {
    T tmp = digitpower(a, (b) / 2);
    if (mode == 0) {
      tmp %= d9_7;
    }
    tmp *= tmp;
    if (mode == 0) {
      tmp %= d9_7;
    }
    if (mode == 0) {
      return (tmp) % d9_7;
    } else {
      return tmp;
    }
  }
}
vector<long long> facs(2000008, -1);
long long Factrial(long long num) {
  if (facs[num] != -1) {
    return facs[num];
  }
  if (num == 1 || num <= 0) {
    return 1;
  } else if (num < 0) {
    return 1;
  } else {
    facs[num] = (num * Factrial(num - 1)) % d9_7;
    return facs[num];
  }
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long linercomb(long long n, long long k, long long mod) {
  if (n < k) return 0;
  if (n < 0) return 0;
  long long ans = Factrial(n);
  ans *= modinv(Factrial(k), mod);
  ans %= mod;
  long long k1 = Factrial(n - k);
  k1 %= mod;
  ans *= modinv(k1, mod);
  ans %= mod;
  return ans;
}
long long Permatation(long long n, long long k) {
  if (n < k) {
    return 0;
  }
  return (Factrial(n) * modinv(Factrial(n - k), d9_7)) % d9_7;
}
unordered_map<long long, long long> prime_factor(long long n) {
  unordered_map<long long, long long> ret;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
template <class T>
vector<T> getaccum(vector<T> a, int mode) {
  int size = a.size();
  vector<T> ans(size);
  ans[0] = a[0];
  for (int i = 0; i < size - 1; i++) {
    ans[i + 1] = ans[i] + a[i + 1];
    if (mode == 0) {
      ans[i + 1] %= d9_7;
    }
  }
  return ans;
}
template <class T>
T get_digisum(T n) {
  T ret = 0;
  while (n >= 1) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}
template <class T>
T getdigit(T num, T n) {
  T ans = 0;
  while (num != 0) {
    ans++;
    num /= n;
  }
  return ans;
}
struct edge {
  int to;
  long long length;
  int num;
  int pair;
};
struct treev {
  int num;
  vector<int> nexts;
};
vector<treev> vs;
vector<edge> es;
int cmax = 0;
void createtreenode(int num) {
  vs = vector<treev>(num);
  for (int i = 0; i < num; i++) {
    vs[i].num = i;
  }
  return;
}
void insertree_bidire(long long len, int Va, int Vb, int num) {
  es.push_back({Va, len, num, -1});
  es.push_back({Vb, len, num, -1});
  int size = es.size();
  es[size - 1].pair = size - 2;
  es[size - 2].pair = size - 1;
  vs[Va].nexts.push_back(size - 1);
  vs[Vb].nexts.push_back(size - 2);
  return;
}
void insertree_unidire(long long len, int Va, int Vb, int num) {
  es.push_back({Vb, len, num, -1});
  int size = es.size();
  es[size - 1].pair = -1;
  vs[Va].nexts.push_back(size - 1);
  return;
}
void DFS(int root, long long depth, int pre, int precol) {
  int ncnt = 0;
  for (auto i : vs[root].nexts) {
    if (pre == es[i].to) {
      continue;
    }
    DFS(es[i].to, depth + es[i].length, root, ncnt);
  }
  return;
}
struct operatedata {
  int num;
  int prenum;
  long long depth;
};
deque<operatedata> opera;
vector<int> past;
int tmpdepthmax = 0;
int ngflag = 0;
vector<long long> locs;
void BFS(int ini) {
  opera.clear();
  opera.push_back({ini, -1, 0});
  int pre = -1;
  while (opera.size() != 0 && ngflag == 0) {
    int root = opera.front().num;
    int pre = opera.front().prenum;
    long long depth = opera.front().depth;
    opera.pop_front();
    if (locs[root] != llMAX && root != ini) {
      if (locs[root] == depth) {
        continue;
      } else {
        ngflag = 1;
        break;
      }
    }
    locs[root] = depth;
    for (int i : vs[root].nexts) {
      if (es[i].to == pre) {
        continue;
      }
      opera.push_back({es[i].to, root, depth + es[i].length});
    }
  }
  return;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  createtreenode(n);
  vector<long long> l(m), r(m), d(m);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> d[i];
    l[i]--;
    r[i]--;
  }
  locs = vector<long long>(n, llMAX);
  locs[0] = 0;
  for (int i = 0; i < m; i++) {
    insertree_unidire(d[i], l[i], r[i], i);
    insertree_unidire(-d[i], r[i], l[i], i);
  }
  for (int i = 0; i < n && ngflag == 0; i++) {
    BFS(i);
  }
  if (ngflag == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
