update prim algorithm