Implement bellman ford algorithm