import sys from collections import deque def main(): input = sys.stdin.read().split() ptr = 0 n = int(input[ptr]) ptr += 1 q = int(input[ptr]) ptr += 1 adj = [[] for _ in range(n + 1)] for _ in range(n - 1): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 adj[a].append(b) adj[b].append(a) values = [0] * (n + 1) for _ in range(q): x = int(input[ptr]) ptr += 1 y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 # Output the current value of x print(values[x]) # BFS to update all nodes within y distance visited = [False] * (n + 1) queue = deque() queue.append((x, 0)) visited[x] = True while queue: u, d = queue.popleft() if d > y: break values[u] += z for v in adj[u]: if not visited[v]: visited[v] = True queue.append((v, d + 1)) if __name__ == "__main__": main()