Implementation of the Hungarian algorithm.