Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
dp = [[(-1,0)]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
from itertools import product
for i0,i,u in product(range(10,-1,-1), range(0,11), range(n)):
# for i0 in range(10, -1, -1):
    if i==0:
        for i,v,d,_ in qs:
            if i0<=d:
                dp[0][v] = (i,d)
    else:
#     for i in range(1,11):
#         for u in range(n):
        if dp[i-1][u][0]>dp[i][u][0]:
            ind0, d0 = dp[i-1][u]
        else:
            ind0, d0 = dp[i][u]
        for v in ns[u]:
            ind,d = dp[i-1][v]
            if ind>ind0 and d>0:# and i0<=i+d:
                ind0, d0 = ind, d-1
        dp[i][u] = (ind0, d0)
#     print(dp[10])
write("\n".join(map(str, ((qs[dp[10][u][0]][3] if dp[10][u][0]>=0 else 0) for u in range(n)))))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(list)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
    
dp = [[-1]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
    dp[d][v] = i
from itertools import product
for i,u in product(range(10,0,-1), range(n)):
    if dp[i][u]>=0:
        dp[i-1][u] = max(dp[i-1][u], dp[i][u])
        for v in ns[u]:
            dp[i-1][v] = max(dp[i-1][v], dp[i][u])

write("\n".join(map(str, ((qs[dp[0][u]][3] if dp[0][u]>=0 else 0) for u in range(n)))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
dp = [[(-1,0)]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
for i0 in range(10, -1, -1):
    for i,v,d,_ in qs:
        if i0<=d:
            dp[0][v] = (i,d)
    for i in range(1,11):
        for u in range(n):
            if dp[i-1][u][0]>dp[i][u][0]:
                ind0, d0 = dp[i-1][u]
            else:
                ind0, d0 = dp[i][u]
            for v in ns[u]:
                ind,d = dp[i-1][v]
                if ind>ind0 and d>0:# and i0<=i+d:
                    ind0, d0 = ind, d-1
            dp[i][u] = (ind0, d0)
#     print(dp[10])
write("\n".join(map(str, ((qs[dp[10][u][0]][3] if dp[10][u][0]>=0 else 0) for u in range(n)))))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(list)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
    
dp = [[-1]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
    dp[d][v] = i
from itertools import product
for i,u in product(range(10,0,-1), range(n)):
    if dp[i][u]>=0:
        dp[i-1][u] = max(dp[i-1][u], dp[i][u])
        for v in ns[u]:
            dp[i-1][v] = max(dp[i-1][v], dp[i][u])

write("\n".join(map(str, ((qs[dp[0][u]][3] if dp[0][u]>=0 else 0) for u in range(n)))))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)
dp = [[(-1,0,0)]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
for i0 in range(10, -1, -1):
    for i,v,d,c in qs:
        if i0<=d:
            dp[0][v] = (i,c,d)
    for i in range(1,11):
        for u in range(n):
            if dp[i-1][u][0]>dp[i][u][0]:
                ind0, c0, d0 = dp[i-1][u]
            else:
                ind0, c0, d0 = dp[i][u]
            for v in ns[u]:
                ind,c,d = dp[i-1][v]
                if ind>ind0 and d>0 and i0<=i+d:
                    ind0, c0, d0 = ind, c, d-1
            dp[i][u] = (ind0, c0, d0)
#     print(dp[10])
write("\n".join(map(str, (dp[10][u][1] for u in range(n)))))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,m = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(list)
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)
    
dp = [[-1]*n for _ in range(11)]
q = int(input())
qs = [None]*q
for i in range(q):
    v,d,c = tuple(map(int, input().split()))
    v -= 1
    qs[i] = (i,v,d,c)
    dp[d][v] = i
from itertools import product
for i,u in product(range(10,0,-1), range(n)):
    if dp[i][u]>=0:
        dp[i-1][u] = max(dp[i-1][u], dp[i][u])
        for v in ns[u]:
            dp[i-1][v] = max(dp[i-1][v], dp[i][u])

write("\n".join(map(str, ((qs[dp[0][u]][3] if dp[0][u]>=0 else 0) for u in range(n)))))