#include <bits/stdc++.h>
using namespace std;
const int Max = 200002;
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    int mp[Max];
    int father[Max];
    int flag = 1;
    for (int i = 0; i <= n; i++) father[i] = i;
    for (int i = 0; i < m; i++) {
      int xl, xr, d;
      cin >> xl >> xr >> d;
      if (d != 0) {
        if (father[xl] == father[xr]) {
          flag = 0;
        } else
          father[xr] = father[xl];
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
