vector graph[100001];
bool visited[100001];
//DFS traversal function of graph
/*time complexity = O(n+m)
where,n = no of vertices and m = no of edges
-->Stack data structure is used
*/
void dfs(int s)
{
if (visited[s])
return;
visited[s] = true;
cout << s << " ";
for (int i = 0; i < graph[s].size(); ++i)
{
if (visited[graph[s][i]] == false)
dfs(graph[s][i]);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter