From c9c7c75e52acf188d88ea7d0b180d67f83e88166 Mon Sep 17 00:00:00 2001 From: Rishabh Kumar <52632726+rishabhk965@users.noreply.github.com> Date: Wed, 13 Oct 2021 14:49:56 +0530 Subject: [PATCH] added bellmanford.cpp --- dynamic_programming/bellmanford.cpp | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 dynamic_programming/bellmanford.cpp diff --git a/dynamic_programming/bellmanford.cpp b/dynamic_programming/bellmanford.cpp new file mode 100644 index 00000000..7f980020 --- /dev/null +++ b/dynamic_programming/bellmanford.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; +int main() +{ + int v,e; + cin>>v>>e; + vector< pair > adj[v]; + for(int i=0;i>src>>dest>>w; + adj[src].push_back({dest,w}); + } + int src; + cin>>src; + int dist[v]; + for(int i=0;i(dist[s]+w) && dist[s]!=INT_MAX) + { + dist[d] = dist[s] + w; + } + } + } + } + bool x=true; + for(int j=0;jdist[s]+w && dist[s]!=INT_MAX) + { + x = false; + } + } + } + for(int i=0;i