Can Someone help me with what's wrong in my code?

I have been trying to solve Problem Two Closest and here is my solution Solution I am getting wrong on only one test case and I have tried to find the mistake but couldn’t.

My Approach : I tried using bfs on the graph for all the special nodes and when the distance of a child in bfs would be greater than global minimum distance i would break the bfs on current special node and carry on with further special nodes (Trying to follow same approach as in editorial).

Can Someone plz help me with this ?

3 3 2
1 3
1 2 10
2 3 5
1 3 20

Correct Answer - 15
Your Answer - 20

I am not sure how you got AC in most of the test cases as according to your solution if two special nodes have a direct path then an indirect path of smaller weight is not even considered, as it will be marked visited while travelling from one special node to the other special node.

Thanks @lotthbrok i got AC , can you please review my correct submission once to see if there is still any issue? Solution

Now it looks fine as now count of special nodes is maintained correctly to compare the distance.

1 Like

Thanks @lotthbrok for helping