Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for dist[it.u] != INF in Bellman Ford Algo #12

Open
ParagSaini opened this issue Jun 27, 2021 · 0 comments
Open

Checking for dist[it.u] != INF in Bellman Ford Algo #12

ParagSaini opened this issue Jun 27, 2021 · 0 comments

Comments

@ParagSaini
Copy link

ParagSaini commented Jun 27, 2021

Don't we have to check for dist[it.u] != INF before adding it.wt. Because if we have negative weight this will become less to INF, and can change the dist[it.v]?
like code may be :

for(int i = 1;i<=N-1;i++) { for(auto it: edges) { if(dist[it.u] != INF && (dist[it.u] + it.wt) < dist[it.v]) { dist[it.v] = dist[it.u] + it.wt; } } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant