Implement johnson's algorithm