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

inf = float("inf")
N, M = list(map(int, input().split()))
to = [[] for x in range(N+1)]
cost = [[] for x in range(N+1)]
value = [inf for x in range(N+1)]

for i in range(M):
    l, r, d = list(map(int, input().split()))
    to[l].append(r)
    cost[l].append(d)
    to[r].append(l)
    cost[r].append(-d)

for i in range(1, N+1):
    if value[i] != inf: continue
    
    value[i] = 0
    q = Queue()
    q.put(i)
    while not q.empty():
        tmp = q.get()
        for j in range(len(to[tmp])):
            nxt = to[tmp][j]
            nxt_val = value[tmp] + cost[tmp][j]
            if value[nxt] != inf:
                if value[nxt] == nxt_val: continue
                print("No")
                sys.exit()
            value[nxt] = nxt_val
            q.put(nxt)
print("Yes")

Fixed submission:
from queue import Queue
import sys

inf = float("inf")
N, M = list(map(int, input().split()))
dist = [[] for x in range(N+1)]
value = [inf for x in range(N+1)]

for i in range(M):
    l, r, d = list(map(int, input().split()))
    dist[l].append((r, d))
    dist[r].append((l, -d))

for i in range(1, N+1):
    if value[i] != inf: continue
    
    value[i] = 0
    q = Queue()
    q.put(i)
    while not q.empty():
        tmp = q.get()
        for x in dist[tmp]:
            nxt = x[0]
            nxt_val = value[tmp] + x[1]
            if value[nxt] != inf:
                if value[nxt] == nxt_val: continue
                print("No")
                sys.exit()
            value[nxt] = nxt_val
            q.put(nxt)
print("Yes")

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

inf = float("inf")

class Node:
    def __init__(self):
        self.to = []
        self.cost = []
        self.value = inf
        self.done = False

    def __str__(self):
        return "to = {0}, cost = {1}, value = {2}".format(self.to, self.cost, self.value)

N, M = list(map(int, input().split()))
I = [Node() for x in range(N+1)]

for i in range(M):
    l, r, d = list(map(int, input().split()))
    I[l].to.append(r)
    I[l].cost.append(d)
    I[r].to.append(l)
    I[r].cost.append(-d)

for i in I:
    if i.done: continue
    
    i.value = 0
    q = Queue()
    q.put(i)
    while not q.empty():
        tmp = q.get()
        for j in range(len(tmp.to)):
            nxt = I[tmp.to[j]]
            nxt_val = tmp.value + tmp.cost[j]
            if nxt.done:
                if nxt.value == nxt_val: continue
                print("No")
                sys.exit()
            nxt.value = nxt_val
            nxt.done = True
            q.put(nxt)
print("Yes")

Fixed submission:
from queue import Queue
import sys

inf = float("inf")
N, M = list(map(int, input().split()))
dist = [[] for x in range(N+1)]
value = [inf for x in range(N+1)]

for i in range(M):
    l, r, d = list(map(int, input().split()))
    dist[l].append((r, d))
    dist[r].append((l, -d))

for i in range(1, N+1):
    if value[i] != inf: continue
    
    value[i] = 0
    q = Queue()
    q.put(i)
    while not q.empty():
        tmp = q.get()
        for x in dist[tmp]:
            nxt = x[0]
            nxt_val = value[tmp] + x[1]
            if value[nxt] != inf:
                if value[nxt] == nxt_val: continue
                print("No")
                sys.exit()
            value[nxt] = nxt_val
            q.put(nxt)
print("Yes")