from collections import defaultdict, deque

N, M = list(map(int, input().split()))

used = [True]*N

dic = defaultdict(list)

for i in range(M):

  l, r, d = list(map(int,input().split()))

  l -= 1

  r -= 1

  used[r] = False

  dic[l] += [(r,d)]



dist = [-1]*N

q = deque([])

for i in range(N):

  if used[i]:

    q += [i]

    dist[i] = 0



ans = True

while q:

  e = q.popleft()

  flag = False

  for p, d in dic[e]:

    if dist[p]==-1:

      dist[p] = d+dist[e]

      q += [p]

    elif dist[p]!=dist[e]+d:

      ans = False

      flag = True

      break

  if flag:

    break

if ans:

  if -1 not in dist:

    print('Yes')

  else:

    print('No')

else:

  print('No')
from collections import deque

N, M, *L = list(map(int, open(0).read().split()))

dic = [[] for i in range(N+1)]

llog = set()

rlog = set()

for l,r,d in zip(*[iter(L)]*3):

  dic[l].append((r,d))

  llog.add(l)

  rlog.add(r)

log = llog.difference(rlog)

q = deque(log)

dist = [-1]*(N+1)

for c in log:

  dist[c] = 0

while q:

  v = q.popleft()

  flag = False

  for u,d in dic[v]:

    if dist[u]==-1:

      dist[u] = dist[v]+d

      q.append(u)

    elif dist[u]!=dist[v]+d:

      print('No')

      flag = True

      break

  if flag:

    break

else:

  U = llog.union(rlog)

  for c in U:

    if dist[c]==-1:

      print('No')

      break

  else:

    print('Yes')
from collections import defaultdict, deque

N, M = list(map(int, input().split()))
used = [True] * N
dic = defaultdict(list)
for i in range(M):
    l, r, d = list(map(int, input().split()))
    l -= 1
    r -= 1
    used[r] = False
    dic[l] += [(r, d)]
dist = [-1] * N
q = deque([])
for i in range(N):
    if used[i]:
        q += [i]
        dist[i] = 0
ans = True
while q:
    e = q.popleft()
    flag = False
    for p, d in dic[e]:
        if dist[p] == -1:
            dist[p] = d + dist[e]
            q += [p]
        elif dist[p] != dist[e] + d:
            ans = False
            flag = True
            break
    if flag:
        break
if ans:
    if -1 not in dist:
        print("Yes")
    else:
        print("No")
else:
    print("No")

from collections import deque

N, M, *L = list(map(int, open(0).read().split()))
dic = [[] for i in range(N + 1)]
llog = set()
rlog = set()
for l, r, d in zip(*[iter(L)] * 3):
    dic[l].append((r, d))
    llog.add(l)
    rlog.add(r)
log = llog.difference(rlog)
q = deque(log)
dist = [-1] * (N + 1)
for c in log:
    dist[c] = 0
while q:
    v = q.popleft()
    flag = False
    for u, d in dic[v]:
        if dist[u] == -1:
            dist[u] = dist[v] + d
            q.append(u)
        elif dist[u] != dist[v] + d:
            print("No")
            flag = True
            break
    if flag:
        break
else:
    U = llog.union(rlog)
    for c in U:
        if dist[c] == -1:
            print("No")
            break
    else:
        print("Yes")

-from collections import defaultdict, deque +from collections import deque -N, M = list(map(int, input().split())) -used = [True] * N -dic = defaultdict(list) -for i in range(M): -    l, r, d = list(map(int, input().split())) -    l -= 1 -    r -= 1 -    used[r] = False -    dic[l] += [(r, d)] -dist = [-1] * N -q = deque([]) -for i in range(N): -    if used[i]: -        q += [i] -        dist[i] = 0 -ans = True +N, M, *L = list(map(int, open(0).read().split())) +dic = [[] for i in range(N + 1)] +llog = set() +rlog = set() +for l, r, d in zip(*[iter(L)] * 3): +    dic[l].append((r, d)) +    llog.add(l) +    rlog.add(r) +log = llog.difference(rlog) +q = deque(log) +dist = [-1] * (N + 1) +for c in log: +    dist[c] = 0 -    e = q.popleft() +    v = q.popleft() -    for p, d in dic[e]: -        if dist[p] == -1: -            dist[p] = d + dist[e] -            q += [p] -        elif dist[p] != dist[e] + d: -            ans = False +    for u, d in dic[v]: +        if dist[u] == -1: +            dist[u] = dist[v] + d +            q.append(u) +        elif dist[u] != dist[v] + d: +            print("No") -if ans: -    if -1 not in dist: +else: +    U = llog.union(rlog) +    for c in U: +        if dist[c] == -1: +            print("No") +            break +    else: -    else: -        print("No") -else: -    print("No")