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