bharatim1221's blog

By bharatim1221, history, 3 years ago, In English

Please help me out. I'm getting "Memory Limit exceeded in test 3" in question D of codeforces https://mirror.codeforces.com/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://mirror.codeforces.com/contest/1675/submission/156122315.

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

You are cloning the tree data every time you call dfs() function.

Try something like this:

void dfs(vector<vector<ll>>& tree, ll v)
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.