結果
| 問題 |
No.1038 TreeAddQuery
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:23:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,085 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 82,280 KB |
| 実行使用メモリ | 239,904 KB |
| 最終ジャッジ日時 | 2025-04-15 21:29:19 |
| 合計ジャッジ時間 | 8,190 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 TLE * 1 -- * 18 |
ソースコード
import sys
from collections import deque
def main():
input = sys.stdin.read
data = input().split()
idx = 0
n = int(data[idx])
idx += 1
q = int(data[idx])
idx += 1
adj = [[] for _ in range(n + 1)]
for _ in range(n - 1):
a = int(data[idx])
idx += 1
b = int(data[idx])
idx += 1
adj[a].append(b)
adj[b].append(a)
values = [0] * (n + 1)
for _ in range(q):
x = int(data[idx])
idx += 1
y = int(data[idx])
idx += 1
z = int(data[idx])
idx += 1
print(values[x])
visited = [False] * (n + 1)
queue = deque()
queue.append((x, 0))
visited[x] = True
while queue:
u, d = queue.popleft()
if d > y:
continue
values[u] += z
if d == y:
continue
for v in adj[u]:
if not visited[v]:
visited[v] = True
queue.append((v, d + 1))
if __name__ == "__main__":
main()
lam6er