MIN QUERY QNS dont iunderstand error in my code

i dont think code mein kuch bhi galat hai but giving wrong ans please check

Dont pass tree again and again, declare as global.
Also, update doesnt mean add here. rather replace it.