Dfs code is running infinitely

This is my dfs code, it is running infinitely.
Please help.

void dfsHelper(int src,map<int,string> &visited)

{

cout<<src<<" ";

visited[src]==“gray”;

    for(auto nbr:l[src])
    {
        if(visited[nbr]=="white")
        {
            dfsHelper(nbr,visited);
        }
    }
    visited[src]="black";

}

void dfs(int src)
{
    map<int,string> visited;

    for(auto p:l)
    {
        visited[p.first]="white";
    }

    dfsHelper(src,visited);

}

@shreyaanand2908 hey dont make color of src black again,it will run fine.

No, it is not working.
Plus I have to make the colour of a node dark once all its neighbours are visited. It doesn’t make difference on the logic.

Please help with this!

@shreyaanand2908 hey let me correct your code.

@shreyaanand2908 heh its running fine,ap mujhe question link send krdo ,mein submit krke check krke apko bta dunga.

I found the error, thank you!

@shreyaanand2908 ok good,feel free to ask any doubt ,please close this doubt if you dont have any further issue.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

In dfs, if instead of type bool for the visited map, I have a type string so that initially I want to colour all the nodes as white… as I visit it I want it gray and when all its neighbours are visited, I want it black, it is not working if in a directed graph, a node with no neighbours is present.

@shreyaanand2908
You can use int instead of string
where 0, 1, 2 can be used as colors
For the second query you can see this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.