My RBTREES solution is giving TLE

Problem page: https://www.codechef.com/problems/RBTREES
TLE Solution link: https://www.codechef.com/viewsolution/37112125
I did the exact same thing as given in official editorial but I was getting TLE . Can anyone tell me whats wrong?
I used donor and taker in place of excess and req variables. And ignore the commented lines ( I started with that simple bfs but ended up realizing it could answer only if a solution is possible or not :smile: ). And my dfs function name is solve