Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")


Fixed submission:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")


Fixed submission:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100001)
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")


Fixed submission:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N, M = map(int,input().split())
if M == 0:
    print("Yes")
    exit(0)

INF = float("inf")
G = [[] for k in range(N)]
D = [INF for k in range(N)]
def dfs(x):
    if len(G[x]) == 0:
        D[x] = x
    else:
        for e in G[x]:
            if D[e[0]] == INF:
                D[e[0]] = D[x] + e[1]
                dfs(e[0])
            else:
                if D[e[0]] != D[x] + e[1]:
                    print("No")
                    exit(0)

for k in range(M):
    L, R, S = map(int,input().split())
    G[L-1].append([R-1,S])
    G[R-1].append([L-1,-S])

for k in range(N):
    if D[k] == INF:
        D[k] = k
        dfs(k)
print("Yes")