Блог пользователя EternalFire

Автор EternalFire, история, 5 лет назад, По-английски

Given a connected unweighted undirected graph with N (N <= 100000) vertices and M (M <= 200000) edges (there is no multiedge nor loop). For each bridge in graph determine the size of two subgraphs formed by removing this bridge.

I am trying to solve a problem, but I have just encountered this subproblem when following my approach. Could anyone have an idea to solve above problem? Thanks

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

I would try this approach: Root at some vertex, and calculate size of each subtree, then you can for each edge (u,v) calculate that one subgraph has d[root]-d[v], and other one have size_of_subtree-(d[root]-d[v]). Where d[x] size of subtree with vertex x as root.

»
5 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

I am not sure for my idea, but I will just say what I am thinking and maybe it can help. I will call sub-graphs that are 2-connected as "blocks". So now you can imagine the graph as a tree of blocks, where the nodes of the tree is a bunch of nodes that form a sub-graph which does not have bridge and the edges of the tree are the bridges of the initial graph. With that idea, now maybe you can pre calculate the sizes of subtrees and get the answer you need.

If you think about it and you find it a good idea, I can continue with the specific algorithm I have in my mind.

»
5 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Direct application of Bridge Tree.
If you shrink each component in a node and keep the bridges as edge, then the graph will turn into a tree. Then you can assign component size as weights to node, and solve it for a tree.
There are other applications of this tree, check them out. :)

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is it a problem from any online judge? If so, can you give the link to the problem?

  • »
    »
    5 лет назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

    It's on SPOJ. Unfortunately, I couldn't find any statements of problem in English. But I think I can describe it here:

    Given an undirected graph (doesn't have to be connected) with N vertices (N <= 100000) and M edges (M <= 200000), containing no loop nor multiedge. One operation is following: First, delete an edge of the graph. Then you must add an edge connecting two different vertices which has never been existed before. You should count the number of ways to perform single operation, such that the result graph is connected. Two operations are different with each other if one of the following conditions hold:

    • The edges deleted by two operations are different.

    • The edges added by two operations are different.