Edge test1 and 2 failed

when i run those tests offline on my system i get this error:
terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc
can anyone help me out here?

You tell me what std:bad_alloc is :slight_smile:

https://en.cppreference.com/w/cpp/memory/new/bad_alloc

Are you doing new allocations?

no the code seems to work for number of nodes less than 9000

This is because you are passing vector<vector > graph without reference.
Instead you can declare the graph vector globally of size 10000, so that you do not have to pass in each function call.

1 Like

if i am passing it without reference it should not work for sizes less than 10000, since it is going through recursion

@agentsam007 What @sridherj-criodo and @virali-crio-ta are trying to suggest is that it is a memory allocation issue. Passing params by value or creating new objects in a function causes the program to allocate memory in the stack / heap memory in each successive call - this means in deep recursive calls there is a chance memory might get exhausted. Using reference allocates it once on the heap and thereafter a pointer points to this memory location and declaring upfront also causes memory to be allocated on the heap.

There are many discussions on the internet where you can read more, I found a short one that is concise enough to get started on this path: https://stackoverflow.com/questions/22431902/where-variables-of-a-function-is-store-on-stack-or-heap

Hope this helps.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.