algorithmgraph-algorithmtarjans-algorithm

Collapse vertices after Tarjan found the strongly connected component


Suppose there are many vertices with some value in a circled graph.

After using Tarjan to find out these SCCs, I want to turn each whole SCC into two vertices(not one), one with the highest value among those vertices in this SCC and another with the lowest value.

Let those vertices which are connected to this SCC to point to the vertex with lowest value, and let vertices which are pointed at from the SCC to be pointed at from the vertex with highest value.

That is, like 1(4) -> 2(3) <-> 3(5) -> 5(1) <-> 4(6) -> 1(4), weights in the parentheses, which is a circle. I want to translate it into something like 1(4) -> 2(3) -> 3(5) -> 4(1) -> 5(6) , 1(4) -> 4(1)

But I cannot figure out how to implement this, Please help.

I'm using C and adjacency list to store the graph.

Sorry for poor English, I hope it's clear enough to be understood.


Solution

  • the following ideas should get you started:

    you probably need to think about how to resolve ties among max-/min-valuesd nodes in a scc.