← All problemsSign in

Queries on the Tree

You are given a directed tree with N with nodes numbered 1 to N and root at node 1. Each node initially contains 0 coins. You have to handle a total of M operations: 1 L Y : Increase by Y the coins of all nodes which are at a distance L from root. 2 X : Report the sum of coins of all nodes in subtree rooted at node X. Input First line contains N and M. Each of the next N-1 lines contains

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start