that is a quite good approach, it would solve the problem of TLE.

I’m trying to find why I’m getting error so same thing doesn’t happen again in tree problem.

I’ll explain my approach for test case:

4 3

1 2

2 3

2 4

2 10

1 100

3 1

so vector would look something like

1 2 3 4 (index)

2 3

. 4

I have initialized an array with 0 of size n + 1 ---- 1 to n - let it be arr

so for each query, I pass the node(index) and x. for 1, 100 - first it will increase the value of arr[p] += x || arr[1] = 100, then check if this node points to other nodes (1 -> 2) then call solve function again with p = 2, arr[2] += x, 2 points (2 -> 3, 4) similarly increment a[3], a[4] by x, since a[3] doesn’t point to any node its vector size is 0.

solve function

void solve(vector & ma, vector& arr, int p, int &x)

{

arr[p] += x;

```
if(!ma[p].empty())
{
for(auto c: ma[p])
solve(ma, arr, c, x);
}
}
```

here ma is the 2d vector, arr is initialized with 0, p is the node and x is the value to increment.