Buggy python submission (verdict: Time Limit Exceeded):
import queue

n,m = map(int,input().split())

dis = [[] for i in range(n)]

for i in range(m):
    g1,g2,L =  map(int,input().split())
    dis[g1-1].append((g2-1,L))
    dis[g2-1].append((g1-1,-L))




geo = [0.5] * n

q = queue.Queue()


for i in range(n):
    if geo[i] == 0.5:
        q.put(i)
        while not q.empty():
            g1 = q.get()
            for g2,L in dis[g1]:
                if geo[g2] == 0.5:
                    geo[g2] = geo[g1] + L
                    q.put(g2)
                else:
                    if geo[g2] != geo[g1] + L:
                        print("No")
                        exit()
print("Yes")




Fixed submission:
import collections
from collections import deque
import sys
input = sys.stdin.readline
 
def bfs(s):
    d = deque()
    d.append(s)
    dis[s]=0
    flag=True
    while len(d):
        x = d.popleft()
        for i,j in vec[x]:
            if dis[i] == INF:
                dis[i]=dis[x]+j
                d.append(i)
 
            else:
                if dis[i]==dis[x]+j:
                    continue
                else:
                    print('No')
                    exit()
    return flag
 
 
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
vec= [[] for i in range(n)]
 
for i in range(m):
    vec[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    vec[a[i][1]-1].append((a[i][0]-1,-a[i][2]))
 
INF=float('inf')
dis=[INF]*n
 
for i in range(n):
    if dis[i]==INF:
        bfs(i)
print('Yes')

Buggy python submission (verdict: Runtime Error):
import queue

n,m = map(int,input().split())

dis = [[] for i in range(n)]

for i in range(m):
    g1,g2,L =  map(int,input().split())
    dis[g1-1].append((g2-1,L))
    dis[g2-1].append((g1-1,-L))




geo = [0.5] * n

q = queue.Queue()


for i in range(m):
    if geo[i] == 0.5:
        q.put(i)
        while not q.empty():
            g1 = q.get()
            for g2,L in dis[g1]:
                if geo[g2] == 0.5:
                    geo[g2] = geo[g1] + L
                    q.put(g2)
                else:
                    if geo[g2] != geo[g1] + L:
                        print("No")
                        exit()
print("Yes")



"""
q = queue.Queue(0)
for i in range(1,5):
    q.put(i)
q.put(4)
while not q.empty():
    print(q.get())
"""


Fixed submission:
import collections
from collections import deque
import sys
input = sys.stdin.readline
 
def bfs(s):
    d = deque()
    d.append(s)
    dis[s]=0
    flag=True
    while len(d):
        x = d.popleft()
        for i,j in vec[x]:
            if dis[i] == INF:
                dis[i]=dis[x]+j
                d.append(i)
 
            else:
                if dis[i]==dis[x]+j:
                    continue
                else:
                    print('No')
                    exit()
    return flag
 
 
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
vec= [[] for i in range(n)]
 
for i in range(m):
    vec[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    vec[a[i][1]-1].append((a[i][0]-1,-a[i][2]))
 
INF=float('inf')
dis=[INF]*n
 
for i in range(n):
    if dis[i]==INF:
        bfs(i)
print('Yes')