Please help me out. I'm getting "Memory Limit exceeded in test 3" in question D of codeforces https://codeforces.net/problemset/problem/1675/D. I can't figure out where I'm doing wrong. Kindly help me out.
I'm attaching my code here. https://codeforces.net/contest/1675/submission/156122315.
You are cloning the tree data every time you call dfs() function.
Try something like this:
A small note for you:
These type of questions can be asked in the tutorial blog of that contest. Creating a new blog to ask about simple problems with your solution is disturbing for the community as all the posts appear in the homepage as long as it's active.
Don't take it personally. Thanks.
I apologize for it.