Prims algorithm distance matrix