mercyme's blog

By mercyme, history, 16 months ago, In English

I am trying to solve the problem J: Computer Networks here: https://mirror.codeforces.com/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://mirror.codeforces.com/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.

Full text and comments »

  • Vote: I like it
  • +6
  • Vote: I do not like it