Buggy python submission (verdict: Time Limit Exceeded):
# Union Find 木
from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    if i < j:
        parent[i] += parent[j]
        parent[j] = i
    else:
        parent[j] += parent[i]
        parent[i] = j


setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
LRD = [tuple(map(int, input().split())) for _ in range(M)]
LRD.sort()

parent = [-1] * (N + 1)
for L, R, D in LRD:
    unite(parent, L, R)

d = {}
for i in range(1, N + 1):
    if parent[i] < 0:
        d[i] = 0

q = []
for L, R, D in LRD:
    if L > R:
        L, R = R, L
        D = -D
    q.append((L, R, D))

while q:
    nq = []
    for L, R, D in q:
        if L in d and R in d:
            if d[L] + D != d[R]:
                print('No')
                exit()
        elif L in d:
            d[R] = d[L] + D
        elif R in d:
            d[L] = d[R] - D
        else:
            nq.append((L, R, D))
    q = nq
print('Yes')


Fixed submission:
N, M = map(int, input().split())

links = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    links[L].append((R, D))
    links[R].append((L, -D))

t = [None] * (N + 1)
for i in range(1, N + 1):
    if t[i] is not None:
        continue
    t[i] = 0
    s = [i]
    while s:
        j = s.pop()
        for k, l in links[j]:
            if t[k] is None:
                t[k] = t[j] + l
                s.append(k)
            else:
                if t[k] != t[j] + l:
                    print('No')
                    exit()
print('Yes')

Buggy python submission (verdict: Runtime Error):
# Union Find 木
from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    if i < j:
        parent[i] += parent[j]
        parent[j] = i
    else:
        parent[j] += parent[i]
        parent[i] = j


setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
LRD = [tuple(map(int, input().split())) for _ in range(M)]
LRD.sort()

parent = [-1] * (N + 1)
for L, R, D in LRD:
    unite(parent, L, R)

d = {}
for i in range(1, N + 1):
    if parent[i] < 0:
        d[i] = 0

q = []
for L, R, D in LRD:
    if L > R:
        L, R = R, L
        D = -D
    q.append(L, R, D)

while q:
    nq = []
    for L, R, D in q:
        if L in d and R in d:
            if d[L] + D != d[R]:
                print('No')
                exit()
        elif L in d:
            d[R] = d[L] + D
        elif R in d:
            d[L] = d[R] - D
        else:
            nq.append((L, R, D))
    q = nq
print('Yes')


Fixed submission:
N, M = map(int, input().split())

links = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    links[L].append((R, D))
    links[R].append((L, -D))

t = [None] * (N + 1)
for i in range(1, N + 1):
    if t[i] is not None:
        continue
    t[i] = 0
    s = [i]
    while s:
        j = s.pop()
        for k, l in links[j]:
            if t[k] is None:
                t[k] = t[j] + l
                s.append(k)
            else:
                if t[k] != t[j] + l:
                    print('No')
                    exit()
print('Yes')