mercyme's blog

By mercyme, history, 17 months ago, In English

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

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

| Write comment?
»
17 months ago, # |
Rev. 2   Vote: I like it +11 Vote: I do not like it

Notice that the problem wants you to input from a file and output to a file (input.txt / output.txt):

You are reading from standard input and writing to standard output.