Hungarian Method (bipartite graph version) implementation from http://www.frc.ri.cmu.edu/~lantao/codes/hungarian.php