[Solved] vector a[n] allocated in stack or heap? Difference between the declarations vectora(n) and vectora[n]? [duplicate]


vector<int> adj[n];

This is not legal C++ code, you are not allowed to declare a dynamicaly sized array on the stack like this.

It’s also probably the cause of your issue, as making such a huge allocation on the stack can cause some major issues.

You should use the following instead:

vector<vector<int>> adj(n);

6

solved vector a[n] allocated in stack or heap? Difference between the declarations vector>a(n) and vectora[n]? [duplicate]