S.P.A.R.K's blog

By S.P.A.R.K, history, 3 years ago, In English

I was trying to solve 1529C - Parsa's Humongous Tree.

i used the below code which gave memory limit exceeded.

117290969

then i used fill() instead of clear() function which was also used in the tutorials. And i got my soln ac.

117291317

I used clear() in first code whereas fill() in the later one. WHAT IS THE DIFFERENCE BETWEEN THOSE TWO??

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

»
3 years ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

The graph is 1-indexed but you are not clearing adj[n]. That's why you get MLE.

If you change for(int i = 0; i < n ; i ++) to for(int i = 1 ; i <= n ; i ++) you'll get AC.

modified code

»
3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Thanks a lot.