Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Subtree Sum Queries

A tree with n nodes is rooted at node 1 and every node has a value. For each query node x print the sum of values in the subtree of x.

Constraints

1 <= n, q <= 10^5 |value| <= 10^4

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.