-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathgraph_dfs.cpp
More file actions
47 lines (47 loc) · 970 Bytes
/
graph_dfs.cpp
File metadata and controls
47 lines (47 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//#include <bits/stdc++.h>
//using namespace std;
//
//void addEdge(vector<int> adj[], int u,int v)
//{
// adj[u].push_back(v);
// //can also be done for undirected graph
// // by addding this adj[v].push_back(u);
//}
//
//void DFS(vector <int> adj[],int s,int V)
//{
// vector <bool> vis(V,false);
// stack <int> stack;
// stack.push(s);
// while(!stack.empty())
// {
// s=stack.top();
// stack.pop();
// if(!vis[s])
// {
// cout<<s<<" ";
// vis[s]=true;
// }
// for(auto j:adj[s])
// {
// if(!vis[j])
// {
// stack.push(j);
// }
// }
// }
//}
//
//int main() {
// int n,k;
// cin>>n>>k;
// vector<int> adj[n];
// for(int i=0;i<k;i++)
// {
// int a,b;
// cin>>a>>b;
// addEdge(adj,a,b);
// }
// DFS(adj,2,n);
// return 0;
//}