The Euler tour technique converts subtree queries to range queries. Perform a DFS and record each node when you enter and exit.
A node 's subtree corresponds to a contiguous range in this tour. Store (entry time) and (exit time).
The subtree of contains exactly nodes with entry times in . Now subtree sum, subtree min, and similar queries become range queries on an array.
Use a segment tree or Fenwick tree on the tour. Time: . Space: .