Moody_Nabil's blog

By Moody_Nabil, history, 7 weeks ago, In English

I am stuck on this following problem for a pretty long time.

Given a connected undirected graph with n nodes and m edges and the capacity of each edge is 1. maxFlow(u,v) defines the maximum flow from node u to node v. You have to find out how many pair of nodes (u,v) are there where u<v and maxFlow(u,v)=2 . You can assume that the graph won’t have any self-loop.


You can find the problem here. It will be really helpful if you can provide me with a solution.

  • Vote: I like it
  • -5
  • Vote: I do not like it

7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

A pair $$$(u,v)$$$ should be counted when $$$u$$$ and $$$v$$$ are in the same 2-edge-connected component, but not in the same 3-edge-connected component. (This is Menger's theorem.) So you can find the 2- and 3-edge-connected components, and then it's an easy combinatorics problem to extract the answer from their sizes.

Finding 2-edge-connected components is well-known to be possible with little more than normal DFS and is also called bridge-finding. There are many resources available on this topic. See, for example, this blog for details. There are also fast algorithms for finding 3-edge-connected components in the literature but these aren't as widely known and I'm not personally familiar with them.