Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def graph_input(N, M):
    G = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, readline().split())
        G[a].append(b)
        G[b].append(a)
    ind = np.cumsum(list(map(len, G)))
    G = np.concatenate(G).astype(np.int32)
    return G, ind

def main(N, G, ind, V, D, C):
    # 強さ n で塗った時刻
    dp = np.full((N + 1, 11), -1, np.int32)
    for t in range(len(V)):
        v, d = V[t], D[t]
        dp[v, d] = t
    for n in range(10, 0, -1):
        for v in range(1, N + 1):
            dp[v, n - 1] = max(dp[v, n - 1], dp[v, n])
            for i in range(ind[v - 1], ind[v]):
                w = G[i]
                dp[w, n - 1] = max(dp[w, n - 1], dp[v, n])
    dp = dp[:, 0]
    for v in range(1, N + 1):
        t = dp[v]
        c = C[t] if t != -1 else 0
        print(c)

signature = '(i8,i4[:],i4[:],i4[:],i4[:],i4[:])'
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

N, M = map(int, readline().split())
G, ind = graph_input(N, M)
Q = int(readline())
nums = np.array(read().split(), np.int32)
V = nums[::3]
D = nums[1::3]
C = nums[2::3]

main(N, G, ind, V, D, C)

Fixed submission:
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]
Q = int(input())
VDC = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

color = [0] * (N+1)
visited = [[False] * 11 for _ in range(N+1)]
# 残り体力 x で訪れた
# 10で訪れたら、9,8,7も埋める

for v,d,c in VDC[::-1]:
    if visited[v][d]:
        continue
    if color[v] == 0:
        color[v] = c
    for i in range(d+1):
        visited[v][i] = True
    q = [v]
    for t in range(d-1,-1,-1):
        qq = []
        for v in q:
            for w in graph[v]:
                if visited[w][t]:
                    continue
                for i in range(t+1):
                    visited[w][i] = True
                if color[w] == 0:
                    color[w] = c
                qq.append(w)
        q = qq

print('\n'.join(map(str,color[1:])))

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def graph_input(N, M):
    G = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, readline().split())
        G[a].append(b)
        G[b].append(a)
    ind = np.cumsum(list(map(len, G)))
    G = np.concatenate(G).astype(np.int32)
    return G, ind

def main(N, G, ind, V, D, C):
    # 強さ n で塗った時刻
    dp = np.full((N + 1, 11), -1, np.int32)
    for t in range(len(V)):
        v, d = V[t], D[t]
        dp[v, d] = t
    for n in range(10, 0, -1):
        for v in range(1, N + 1):
            dp[v, n - 1] = max(dp[v, n - 1], dp[v, n])
            for i in range(ind[v - 1], ind[v]):
                w = G[i]
                dp[w, n - 1] = max(dp[w, n - 1], dp[v, n])
    dp = dp[:, 0]
    for v in range(1, N + 1):
        t = dp[v]
        c = C[t] if t != -1 else 0
        print(c)

signature = '(i8,i4[:],i4[:],i4[:],i4[:],i4[:])'
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

N, M = map(int, readline().split())
G, ind = graph_input(N, M)
Q = int(readline())
nums = np.array(read().split(), np.int32)
V = nums[::3]
D = nums[1::3]
C = nums[2::3]

main(N, G, ind, V, D, C)

Fixed submission:
import sys
input = sys.stdin.readline

N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]
Q = int(input())
VDC = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

color = [0] * (N+1)
visited = [[False] * 11 for _ in range(N+1)]
# 残り体力 x で訪れた
# 10で訪れたら、9,8,7も埋める

for v,d,c in VDC[::-1]:
    if visited[v][d]:
        continue
    if color[v] == 0:
        color[v] = c
    for i in range(d+1):
        visited[v][i] = True
    q = [v]
    for t in range(d-1,-1,-1):
        qq = []
        for v in q:
            for w in graph[v]:
                if visited[w][t]:
                    continue
                for i in range(t+1):
                    visited[w][i] = True
                if color[w] == 0:
                    color[w] = c
                qq.append(w)
        q = qq

print('\n'.join(map(str,color[1:])))