1

Question:

Given an undirected graph with N nodes and M edges. Given Q queries, there are 2 types of query:

  • 1 - A - B - U - V

Check if there's a path between the node A and B after you remove the edge U-V

  • 2 - A - B - X

Check if there's a path between the node A and B after you remove the node X

Constraints:

N <= 100000
M <= 500000
Q <= 100000

P/S:

I think that the only way there's path between A and B after the removal is that A, B is in the same Biconnected Component or the edge/node is not a bridge/arc.

But since we only have logN time for each query (because there're at most 100.000 queries), I can't find a way to check if A, B is in the same Biconnected Component in O(logN).

Is there a way to do it? Or is there a different solution to this problem?

unglinh279
  • 675
  • 4
  • 24
  • 1
    [https://en.wikipedia.org/wiki/Dynamic_connectivity#Fully_dynamic_connectivity](https://en.wikipedia.org/wiki/Dynamic_connectivity#Fully_dynamic_connectivity)? – גלעד ברקן Oct 25 '21 at 13:23
  • 1
    You're on the right track; it's biconnected components on the original graph, least common ancestors, and a whole lotta details. (@גלעדברקן, those algorithms could also work, but they're IMO more complicated, and the constants are bad.) – David Eisenstat Oct 25 '21 at 14:06

1 Answers1

-1

The simple way to do this is a depth first search, starting at A and stopping and returning true if it reaches B, returning false if B cannot be reached.

It would be useful to know what your actual performance requirement is in seconds.

The PathFinder Graph Theory Engine can check if two random nodes are connected in a graph containing 403,394 nodes and 3,387,388 links with a mean time 0.14 seconds ( 100 tests of different random nodes )

Your graphs are about 4 to 10 times smaller, so I guess it could be done in well under a tenth of a second.

For 100,000 queries that would be less than 3 hours.

You would have to post you test graph to get a more accurate measure of performance.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103