Munkres (aka Hungarian) algorithm for JS