TheCreator's blog

By TheCreator, history, 3 hours ago, In English

Given a connected undirected graph consisting of N N nodes, determine how many connected components the graph will break into if each node is removed.

For example, consider a graph with the following undirected edges:

1-2, 1-3, 1-4, 4-5, 5-6, 4-6.

If we remove node 1, there will be 3 connected components. If we remove node 2, there will be 1 connected component. If we remove node 3, there will be 1 connected component. If we remove node 4, there will be 2 connected components. If we remove node 5, there will be 1 connected component. If we remove node 6, there will be 1 connected component.

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by TheCreator (previous revision, new revision, compare).

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Find all bridges using Tarjan's algorithm. For each node count number of bridges it is connected to.

If X is number of connected components at the beginning and node i is connected to b[i] bridges, then after node i is removed there will be X+b[i] components.

Theres a special case where a single node is by itself, in which case the number of connected components decreases by 1.

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Actually, you need to count the number of articulation points, not the number of bridges, you can see why by this example:

    1 2

    1 3

    3 2

    2 4

    2 5

    4 5

    here, there isn't any bridge but by removing node 2, there gonna be two connected components

    • »
      »
      »
      2 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I don't know how to quickly calculate the number of connected components by removing each articulation point, still thinking about it

»
2 hours ago, # |
  Vote: I like it +1 Vote: I do not like it
  • »
    »
    29 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    bro has every single graph problems as a callable function in his library, holy shit