結果
問題 |
No.1038 TreeAddQuery
|
ユーザー |
![]() |
提出日時 | 2025-06-12 20:26:18 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,079 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 82,756 KB |
実行使用メモリ | 78,976 KB |
最終ジャッジ日時 | 2025-06-12 20:27:02 |
合計ジャッジ時間 | 9,019 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 18 |
ソースコード
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 edges = [[] for _ in range(N+1)] for _ in range(N-1): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 edges[a].append(b) edges[b].append(a) weight = [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 print(weight[X]) if Y == 0: weight[X] += Z continue visited = [False] * (N + 1) q = deque() q.append((X, 0)) visited[X] = True while q: u, d = q.popleft() if d > Y: continue weight[u] += Z for v in edges[u]: if not visited[v]: visited[v] = True q.append((v, d + 1)) if __name__ == '__main__': main()