Calculate the minimum cost with the graph Data structure topic c++