Detailed shrink algorithm of point

Pre-skills: Tarjan seeking strongly connected component

Shrink point .

As the name suggests, an algorithm is shrunk to a point at some point in the graph theory algorithms.

  • application

Seemingly I understand, but this is what use is it?

We often find the shortest path, but if we ask longest way?

Standard question is asked:

Give you a directed graph, each point has a point right (not the right side, oh), and each point can pass any number of times, but the only plus point right time, find this picture maximum weight value

Topic analysis:

See this, I believe most people will think of the most short-template change on the line, but this will go wrong, you will turn round and round in a circle.

How do you do?

We will find, as long as it can constitute a pile of points strongly connected component, we they can be shrunk to a point, and this point is their right point and the right point, it is the side of the side all of their points , the edge is an edge all their points.

Put a few pictures help to understand:

404

404

1.3.5 figure above is a strongly connected components

  • How to achieve?

We opened when an array tarjan Strongly connected component is called color[](或其他名字)to record a point strongly connected component number belongs. So we can through each point, it can point to see if it reaches the same and in the same strongly connected component, if not, they are strongly connected component number is again relying construct a directed acyclic graph (like a I thought, why should rely on numbers)

  • Code
for(int i=1;i<=n;i++)
    {
        for(int j=0;j<ver[i].size();j++)
        {
            int x=ver[i][j];
            if(color[i]!=color[x])
            {
                in[color[x]]++;
                g[color[i]].push_back(color[x]);
            }
        }
    }
    for(int i=1;i<=n;i++)
        ww[color[i]]+=w[i];//点权处理

So that we achieve a reduction point.

  • topic:

[APIO2009] looting plan

Guess you like

Origin www.cnblogs.com/hulean/p/11123016.html