unglinh279
unglinh279

Reputation: 673

Count pair of nodes that can't reach each other if you for each deleted edge

Question:

Given a undirected graph of N nodes and M edges. You need to solve 2 problems:

Example:

N = 6, M = 7
1 2
2 3
3 1
3 4
4 5
5 6
6 4

(Edges are described as u - v)

Result:

P/S: I have been thinking for many days but can't find a proper answer for this problem

Upvotes: 1

Views: 575

Answers (1)

MBo
MBo

Reputation: 80197

IF initial graph is connected, then the first problem is searching of bridges and the second one is searching of cut vertex / articulation points.

After revealing of bridge get sizes of connected components (there are two of them) and needed result is product of sizes (for example, components of size 2 and size 3 give 6 pairs)

After revealing of cut vertex number of components might be larger, and result is sum of pairwise products of sizes (for components with sizes 1,2,3 result is 1*2+1*3+2*3=11 pairs)

C++ code for solving both problems using DFS could be found here

Upvotes: 2

Related Questions