From 1c0cf06232558e0cb06ea09c2b09093e65013294 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar <52632726+rishabhk965@users.noreply.github.com> Date: Wed, 13 Oct 2021 14:43:21 +0530 Subject: [PATCH 1/2] added DFS/cpp --- cpp/DFS.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cpp/DFS.cpp diff --git a/cpp/DFS.cpp b/cpp/DFS.cpp new file mode 100644 index 00000000..a76684e3 --- /dev/null +++ b/cpp/DFS.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; +#define MAXSIZE 1000000 + +vector > graph(MAXSIZE); +bool vis[MAXSIZE]; + + +void dfs(int start) +{ + stack s; + cout<>n; + for(int i=0;i>u>>v; + graph[u].push_back(v); + graph[v].push_back(u); + } + + //to check adjacency list + // for(int i=1;i<=n;i++) + // { + // cout< "; + // for(int j=0;j Date: Wed, 13 Oct 2021 14:46:21 +0530 Subject: [PATCH 2/2] added BFS.cpp --- cpp/BFS.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cpp/BFS.cpp diff --git a/cpp/BFS.cpp b/cpp/BFS.cpp new file mode 100644 index 00000000..9ff21223 --- /dev/null +++ b/cpp/BFS.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#pragma GCC optimize("Ofast") +#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") +#pragma GCC optimize("unroll-loops") +const unsigned int M = 1000000007; +using namespace std; +// Check +using namespace __gnu_pbds; +typedef tree,rb_tree_tag,tree_order_statistics_node_update> T_set; // PBDS_set +typedef tree,rb_tree_tag,tree_order_statistics_node_update> T_multiset; // PBDS_multiset + +void solve() +{ + int n ,m,u,v; + cin>>n>>m; + vector> adj(n+1); + vector vis(n+1,false); + for(int i = 0; i < n ; i++ ){ + cin>>u>>v; + adj[u].push_back(v); + adj[v].push_back(u); + } + queue temp; + temp.push(1); + vis[1] = true; + while(!temp.empty()){ + int curr = temp.front(); + cout<