Category : graph

class graph{ void DFSutil(int v); public: map<int, vector<int> > adj; map<int, bool> visited; map<int, int> color; int twoteams = 1; void DFS(); void addEdge(int u,int v); }; this function adds edge to the graph void graph::addEdge(int u,int v){ adj[u].push_back(v); } depth first search function. i tried to color the child as !parent (in case im ..

Read more

I am recently working with BFS algorithm. I made a maze solving program with this algorithm. here is my code: #include<iostream> #include<cmath> #include<sstream> #include<vector> #include<queue> #include <unistd.h> using namespace std; int m,n; inline int indexFor(int x,int y) { return (x-1) + m*(y-1); } int main() { FILE *file = fopen("test_case","r"); // test_case file //build maze ..

Read more

So, consider the following graph,where ‘this means weight’ 1–‘2’–2–‘5′–5 |’1’ ‘4’ /’1′ src=1 and destination =5 | / Therefore, output = 1+3+1=5 4–‘3′—–3 So my question is can i use bsf instead of dijkstra’s ,since int the tutorial that i am following said that we cannot use the bsf for weighted graph so we have ..

Read more