how to write hungarian algorithm?