We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d419dfa commit c4c0e08Copy full SHA for c4c0e08
DFS.cpp
@@ -0,0 +1,33 @@
1
+/*
2
+Depth First Search is a technique to traverse a tree or a graph.
3
+
4
+*/
5
6
+/* DFS of a Directed tree/graph */
7
+const int M = 1e6+6;
8
9
+vector<int> G[M];
10
+vector<bool> vis(M);
11
12
+void dfs(int u)
13
+{
14
+ vis[u] = true;
15
+ cout << u << endl;
16
+ for(int child : G[u])
17
+ {
18
+ if(!vis[child])
19
+ dfs(child);
20
+ }
21
+}
22
23
+/* DFS of a Undirected tree/graph */
24
+void dfs(int u, int par)
25
26
27
28
29
+ if(child != par)
30
31
32
33
Dfs (Directed Graph).cpp
0 commit comments