it throws error
you have to declare the visited map first map<T,bool> visited;
map<T,bool> visited;
Modified Code