Buggy python submission (verdict: Runtime Error):
class Node:
    def __init__(self, parent, value):
        self.parent = parent
        self.value = value

class UnionFindTree:
    def __init__(self, size):
        self.table = [Node(i, 0) for i in range(size)]
    
    def hoge(self, x):
        while self.table[x].parent != self.table[self.table[x].parent].parent:
            parent = self.table[x].parent
            self.table[x].value += self.table[parent].value
            self.table[x].parent = self.table[parent].value

    def find_root(self, x):
        self.hoge(x)
        return self.table[x].parent

    def find_value(self, x):
        self.hoge(x)
        return self.table[x].value

    def union(self, x, y, d):
        r1 = self.find_root(x)
        r2 = self.find_root(y)
        v1 = self.find_value(x)
        v2 = self.find_value(y)
        print(r1, r2, v1, v2)
        if r1 != r2:
            self.table[r2].parent = r1
            self.table[r2].value = (v1 - v2) + d
        else:
            if (v2 - v1) != d:
                return False
        return True
    
    def __repr__(self):
        return repr(self.table)

def main():
    n, m = map(int, input().split())
    tree = UnionFindTree(n+1)
    for i in range(m):
        li, ri, di = map(int, input().split())
        if not tree.union(li, ri, di):
            print('No')
            return
    print('Yes')

main()


Fixed submission:
class UnionFindTree:
    def __init__(self, size):
        self.parent = list(range(size))
        self.dist = [0] * size

    def find_root(self, x):
        if self.parent[x] == x:
            return x, 0
        else:
            self.parent[x], d = self.find_root(self.parent[x])
            self.dist[x] += d
            return self.parent[x], self.dist[x]

    def union(self, x, y, d):
        r1, d1 = self.find_root(x)
        r2, d2 = self.find_root(y)
        if r1 != r2:
            self.parent[r2] = r1
            self.dist[r2] = (d1 - d2) + d
        else:
            if (d2 - d1) != d:
                return False
        return True

def main():
    n, m = map(int, input().split())
    tree = UnionFindTree(n+1)
    for i in range(m):
        l, r, d = map(int, input().split())
        if not tree.union(l, r, d):
            print('No')
            return
    print('Yes')

main()

Buggy python submission (verdict: Runtime Error):
class Node:
    def __init__(self, parent, value):
        self.parent = parent
        self.value = value

class UnionFindTree:
    def __init__(self, size):
        self.table = [Node(i, 0) for i in range(size)]
    
    def hoge(self, x):
        while self.table[x].parent != self.table[self.table[x].parent].parent:
            parent = self.table[x].parent
            self.table[x].value += self.table[parent].value
            self.table[x].parent += self.table[parent].value

    def find_root(self, x):
        self.hoge(x)
        return self.table[x].parent

    def find_value(self, x):
        self.hoge(x)
        return self.table[x].value

    def union(self, x, y, d):
        r1 = self.find_root(x)
        r2 = self.find_root(y)
        v1 = self.find_value(x)
        v2 = self.find_value(y)
        print(r1, r2, v1, v2)
        if r1 != r2:
            self.table[r2].parent = r1
            self.table[r2].value = (v1 - v2) + d
        else:
            if (v2 - v1) != d:
                return False
        return True
    
    def __repr__(self):
        return repr(self.table)

def main():
    n, m = map(int, input().split())
    tree = UnionFindTree(n+1)
    for i in range(m):
        li, ri, di = map(int, input().split())
        if not tree.union(li, ri, di):
            print('No')
            return
    print('Yes')

main()


Fixed submission:
class UnionFindTree:
    def __init__(self, size):
        self.parent = list(range(size))
        self.dist = [0] * size

    def find_root(self, x):
        if self.parent[x] == x:
            return x, 0
        else:
            self.parent[x], d = self.find_root(self.parent[x])
            self.dist[x] += d
            return self.parent[x], self.dist[x]

    def union(self, x, y, d):
        r1, d1 = self.find_root(x)
        r2, d2 = self.find_root(y)
        if r1 != r2:
            self.parent[r2] = r1
            self.dist[r2] = (d1 - d2) + d
        else:
            if (d2 - d1) != d:
                return False
        return True

def main():
    n, m = map(int, input().split())
    tree = UnionFindTree(n+1)
    for i in range(m):
        l, r, d = map(int, input().split())
        if not tree.union(l, r, d):
            print('No')
            return
    print('Yes')

main()

Buggy python submission (verdict: Time Limit Exceeded):
class UnionFindTree:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
    
    def find_root(self, x):
        while 0 <= self.table[x]:
            x = self.table[x]
        return x

    def union(self, x, y):
        r1 = self.find_root(x)
        r2 = self.find_root(y)
        if r1 != r2:
            self.table[r2] = r1
    
    def __repr__(self):
        return repr(self.table)

def check(root, group, l, r, d):
    seen = set()
    table = {}
    table[root] = 0
    seen.add(root)
    while len(seen) != len(group):
        for li, ri, di in zip(l, r, d):
            if (li not in seen) and (ri not in seen):
                continue
            if (li in seen) and (ri in seen):
                if table[li]+di != table[ri]:
                    return False
            elif li in seen:
                table[ri] = table[li] + di
                seen.add(ri)
            elif ri in seen:
                table[li] = table[ri] - di
                seen.add(li)
    return True

def main():
    n, m = map(int, input().split())
    l, r, d = [], [], []
    seen = set()
    tree = UnionFindTree(n+1)
    for i in range(m):
        li, ri, di = map(int, input().split())
        l.append(li)
        r.append(ri)
        d.append(di)
        seen.add(li)
        seen.add(ri)
        tree.union(li, ri)
    
    groups = {}
    for s in seen:
        root = tree.find_root(s)
        if root not in groups:
            groups[root] = set()
        groups[root].add(s)
    
    for root in groups:
        if not check(root, groups[root], l, r, d):
            print('No')
            return
    print('Yes')

main()


Fixed submission:
class UnionFindTree:
    def __init__(self, size):
        self.parent = list(range(size))
        self.dist = [0] * size

    def find_root(self, x):
        if self.parent[x] == x:
            return x, 0
        else:
            self.parent[x], d = self.find_root(self.parent[x])
            self.dist[x] += d
            return self.parent[x], self.dist[x]

    def union(self, x, y, d):
        r1, d1 = self.find_root(x)
        r2, d2 = self.find_root(y)
        if r1 != r2:
            self.parent[r2] = r1
            self.dist[r2] = (d1 - d2) + d
        else:
            if (d2 - d1) != d:
                return False
        return True

def main():
    n, m = map(int, input().split())
    tree = UnionFindTree(n+1)
    for i in range(m):
        l, r, d = map(int, input().split())
        if not tree.union(l, r, d):
            print('No')
            return
    print('Yes')

main()