How can I replace for loop of DFS() with for_each loop.Please let me know if there's any other efficient way to create graph or any sites teaching Graph through STL that I can basically use for competitive programming?
void DFS(int s)
visited[s] = true;
for(vector<pair<int,int> >::iterator it=AdjList[s].begin();it!=AdjList[s].end();it++)
That loop in DFS is very simple, so I doubt you need to use for_each for that. And for your information,
vector<pair<int,int> >::iterator it=AdjList[s].begin();
can just be
Using auto keyword will reduce much volume from your code.
Well, personally I have implemented all major graph algorithms with STL. Seeing your code, I say you are on the right path to competitive programming already. While boost offers all kinds of readymade libraries, STL is sufficient enough for one to implement graph algorithms with.