code: def prim(G, start, weight='weight'):
      
      if len(connected_components(G)) != 1:
          raise GraphInsertError("Prim algorithm work with connected graph only")
      if start not in G.vertices:
          raise GraphInsertError("Vertex %s doesn't exist." % (start,))
      pred = {}
      key = {}
      pqueue = {}
      lowest = 0
      for edge in G.edges:
          if G.edges[edge][weight] > lowest:
              lowest = G.edges[edge][weight]
      for vertex in G.vertices:
          pred[vertex] = None
          key[vertex] = 2 * lowest
      key[start] = 0
      for vertex in G.vertices:
          pqueue[vertex] = key[vertex]
      while pqueue:
          current = popmin(pqueue, lowest)
          for neighbor in G.vertices[current]:
              if (neighbor in pqueue and
                      G.edges[(current, neighbor)][weight] < key[neighbor]):
                  pred[neighbor] = current
                  key[neighbor] = G.edges[(current, neighbor)][weight]
                  pqueue[neighbor] = G.edges[(current, neighbor)][weight]
      return pred
docs: Algorithm for finding a minimum spanning
      tree for a weighted undirected graph.