basic (not-optimal - to be optimized with heap usage) implementation of
Prim's algorithm