combining queue and prims