Prim's algorithm, in Python.