Prim's O(mn) implementation using scala finished.