I am trying to solve the problem J: Computer Networks here: https://codeforces.me/gym/100114 Basically we have to add one more edge to the graph so that the total number of bridges is minimized. (And the given graph may have multiple edges between two vertices).
What I am doing is that first I find all the bridges (using the technique given here: https://codeforces.me/blog/entry/68138) and while doing so, I also divide the graph into biconnected components and make a tree out of those components. Like so:
Then I just find the longest distance between any two nodes in that tree by first finding the longest distance from a root to a node and then from that node to another node.
I really feel this is correct and my implementation is wrong: https://pastebin.com/NESHhvGm
The problem is that the test cases are not visible either and every code outputs something different. It is difficult to check where I went wrong.
If someone can give me an AC code or any sort of help would be great.