import sys


class UnionFind:
    def __init__(self, MAX_N):
        self.parent = [i for i in range(MAX_N)]
        self.rank = [0 for _ in range(MAX_N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
L = []
R = []
D = []

uf = UnionFind(N)

for i in range(M):
    l, r, d = map(int, input().split())
    L.append(l)
    R.append(r)
    D.append(d)

    if uf.same(l, r):
        if True:
            print('No')
            exit()
    else:
        uf.unite(l, r)

print('Yes')
