Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

def trav(i):
    global g
    global v
    global v_asn
    global f
    for a in g[i]:
        if not v_asn[a[0]]:
            v_asn[a[0]] = True
            v[a[0]] = v[i] + a[1]
            trav(a[0])
        else:
            if v[a[0]] != v[i] + a[1]:
                f = False
                return

for i in range(1, n + 1):
    if not v_asn[i]:
        v_asn[i] = True
        trav(i)
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def d2r(x):
    global par
    global d2p
    k = x
    s = 0
    while k != par[k]:
        s += d2p[k]
        k = par[k]
    return s

def root(x):
    global par
    global d2p
    #print(par, d2p)
    if par[x] == x:
        return x
    else:
        r = root(par[x])
        s = d2r(x)
        par[x] = r
        d2p[x] = s
        return r


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx = root(x)
    dx = d2r(x)
    ry = root(y)
    dy = d2r(y)
    if rx != ry:
        par[rx] = ry
        d2p[rx] = dy + d - dx
        #print(par, d2p,"noz")
        return True
    else:
        if dx - dy != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * m
r = [0] * m
d = [0] * m

for i in range(0, m):
    l[i], r[i], d[i] = [int(j) for j in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def root(x):
    global par
    global d2p
    if par[x] == x:
        return (x, 0)
    else:
        r = root(par[x])
        par[x] = r[0]
        d2p[x] += r[1]
        #print(par, d2p)
        return (r[0], d2p[x])


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx, dx = root(x)
    ry, dy = root(y)
    if rx != ry:
        par[rx] = ry
        d2p[rx] = dy + d - dx
        #print(par, d2p,"noz")
        return True
    else:
        if dx - dy != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * m
r = [0] * m
d = [0] * m

for i in range(0, m):
    l[i], r[i], d[i] = [int(j) for j in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def root(x):
    global par
    global d2p
    if par[x] == x:
        return (x, 0)
    else:
        r = root(par[x])
        par[x] = r[0]
        d2p[x] += r[1]
        #print(par, d2p)
        return (r[0], d2p[x])


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx, dx = root(x)
    ry, dy = root(y)
    if rx != ry:
        par[rx] = ry
        d2p[rx] = dy + d - dx
        #print(par, d2p,"noz")
        return True
    else:
        if dx - dy != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * m
r = [0] * m
d = [0] * m

for i in range(0, m):
    l[i], r[i], d[i] = [int(j) for j in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f and max(d2p) <= 10**9:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def root(x):
    global par
    global d2p
    if par[x] == x:
        return (x, 0)
    else:
        r = root(par[x])
        par[x] = r[0]
        d2p[x] += r[1]
        #print(par, d2p)
        return (r[0], d2p[x])


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx, dx = root(x)
    ry, dy = root(y)
    if rx != ry:
        par[x] = y
        d2p[x] = d
        #print(par, d2p,"noz")
        return True
    else:
        if dy - dx != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * n
r = [0] * n
d = [0] * n

for i in range(0, m):
    l[i], r[i], d[i] = [int(i) for i in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f and max(d2p) <= 10**9:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split(" ")]

par = [i for i in range(0, n + 1)]
d2p = [0 for i in range(0, n + 1)]

def root(x):
    global par
    global d2p
    if par[x] == x:
        return (x, 0)
    else:
        r = root(par[x])
        par[x] = r[0]
        d2p[x] += r[1]
        #print(par, d2p)
        return (r[0], d2p[x])


def unite(x, y, d):
    global par
    global d2p
    #print(x, y, d)
    rx, dx = root(x)
    ry, dy = root(y)
    if rx != ry:
        par[x] = y
        d2p[x] = d
        #print(par, d2p,"noz")
        return True
    else:
        if abs(dx - dy) != d:
            #print(rx, ry, dx, dy)
            return False
        else:
            return True

l = [0] * n
r = [0] * n
d = [0] * n

for i in range(0, m):
    l[i], r[i], d[i] = [int(i) for i in input().split(" ")]

f = True
for i in range(0, m):
    if not unite(l[i], r[i], d[i]):
        f = False
        break

if f and max(d2p) <= 10**9:
    print("Yes")
else:
    print("No")

Fixed submission:
import queue

n, m = [int(i) for i in input().split(" ")]

g = [[] for i in range(0, n + 1)]
v = [0] * (n + 1)
v_asn = [False] * (n + 1)
f = True

for i in range(0, m):
    l, r, d = [int(i) for i in input().split(" ")]
    g[l].append([r, d])
    g[r].append([l, -d])

for i in range(1, n + 1):
    if not v_asn[i]:
        q = queue.Queue()
        v_asn[i] = True
        q.put(i)
        while not q.empty():
            qi = q.get()
            for a in g[qi]:
                if not v_asn[a[0]]:
                    v_asn[a[0]] = True
                    v[a[0]] = v[qi] + a[1]
                    q.put(a[0])
                else:
                    if v[a[0]] != v[qi] + a[1]:
                        f = False
                        break
        if not f:
            break

if f:
    print("Yes")
else:
    print("No")