For those who are getting memory limit exceeded in DFS


If you are using map<int,vector> for adjacency list, it will give memory limit error. Instead of using map<int,vector> m, use vector<vector> m(n+1). Also, if you are using an array to represent teams/ visited array, make sure you are using vectors and not array.