From 3daff45f9fe2857b621778e77c18dbbe08844ee9 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Sat, 9 Oct 2021 21:44:47 +0530 Subject: [PATCH] Delete Bellmen_Ford.cpp Please raise separate PR for this. --- Graph_Algorithms/src/Bellmen_Ford.cpp | 65 --------------------------- 1 file changed, 65 deletions(-) delete mode 100644 Graph_Algorithms/src/Bellmen_Ford.cpp diff --git a/Graph_Algorithms/src/Bellmen_Ford.cpp b/Graph_Algorithms/src/Bellmen_Ford.cpp deleted file mode 100644 index 1bae9bdf..00000000 --- a/Graph_Algorithms/src/Bellmen_Ford.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//Bellmen Ford algorithm to detect negative weight cycle -//Time Complexity is O(V*E) -//Space Complexity is O(V) - -#include -using namespace std; -#define inf INT_MAX - -int main() -{ - int v,e; //V=total vertices e=total edges - cin>>v>>e; - vector>edges; - for(int i=0;i>x>>y>>w; - edges.push_back({x,y,w}); - } - - //dis will store the minimum weight of that vertex - int dis[v]={inf}; - dis[0]=0; - - for(int i=1;i dis[x]+wt) - dis[y]=dis[x]+wt; - } - } - - - int flag=0; - for(int j=0;j dis[x]+wt) - { - dis[y]=dis[x]+wt; - flag=1; - } - } - - // If flag becomes 1 it means weight of vertex is still decreasing Hence is negative weight cycle - if(flag) - cout<<"Yes, this graph has negative weight cycle."; - else - cout<<"No, this graph doesn't have negative weight cycle."; - - return 0; - -} - - -/*Description -If we iterate through all edges v-1 times then it guarantees the shortest distance of vettices. -If we again iterate through all edges one more time and get a shorter path for any vertex, -then there is a negative weight cycle. */