I am solving this problem. And here is the solution. I am using only a simple dfs but it is showing timeout. I am not able to understand why, as time complexity of dfs is O(V + E) and my solution is well within the limits. Can someone help me? Please.
It is probably because last parametr of dfs
runningSumis taken by value instead of by reference. So for eachdfscall new copy of this vector is created.Ohh I didn't noticed it. Thanks