diff --git a/Bellman Ford Algorithm.cpp b/Bellman Ford Algorithm.cpp new file mode 100644 index 0000000..f7f1121 --- /dev/null +++ b/Bellman Ford Algorithm.cpp @@ -0,0 +1,94 @@ +#include +using namespace std; + +struct node{ + int u; + int v; + int wt; + node(int a,int b,int w) + { + u=a; + v=b; + wt=w; + } + +}; + +void BellmanFord(int src,int n,vector adj) +{ + + vector distance(n+1,100000); + distance[src]=0; + + int i,j; + + // Here, Relax all the edges n-1 times as max distance between two nodes in a graph can be n-1 + for(i=0;i>n>>edges; + + vector adj; + + for(i=0;i>a>>b>>wt; + adj.push_back(node(a,b,wt)); + adj.push_back(node(b,a,wt)); // This is for the undirected graph else not needed for directed graph + } + + // for(auto x: adj) cout<