tejas2's blog

By tejas2, history, 10 days ago, In English

Following is my solution for 977E - Cyclic Components (Finding number of cyclic connected components in a graph) :- My Solution : 207324313. Can anyone please tell why am I getting MLE?

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

»
10 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Pass your graph by reference in the dfs function.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

In the dfs function you also have to pass "vector adj" by reference. If you don't pass any data structure by reference then a copy of that data structure is passed in the function, not the original data structure. Thus you are getting MLE.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

You gotta pass by referance or as my personal preferance, declare variables globally. Not only do functions get easier to manage, also you don't have to deal with pointers and referances.

»
10 days ago, # |
  Vote: I like it 0 Vote: I do not like it

I would suggest u to use lamda function

»
9 days ago, # |
  Vote: I like it +4 Vote: I do not like it

pass by reference the adj vector in your dfs function.

Hope you successfully solved it

»
5 days ago, # |
  Vote: I like it +3 Vote: I do not like it

Passing by reference / declaring globally worked. Thanks Everyone