Please help ! Why these two solutions give different verdict

Solution 1
Solution 2

The only difference in above both solutions is:
In solution 1, I have used vector<vector> adj(n+1) for adjacency list while in solution 2, I have used vector adj[n+1] for this list.
Solution 1 memory limit exceeds while solution 2 was accepted.
Why?
Please help!!
Thanks in advance

1 Like

the elements in one case are INTs and LL in the other…too much memory used

1 Like

You should pass the address of vector in dfs like this:
dfs(…, vector<vector >& adj)

1 Like

thanks @carre @nitin_398