Here\'s the code, I used min priority queue of STL here. For small inputs it is working fine, even for medium sized outputs as well but with very big inputs like 500 vertices, i