Connectivity graph

Connectivity graph

[Figure 0.5] pre-knowledge on the concepts dfs

vis array: traversing figure, often a bool value is set to a recording mark array vis whether the vertices are visited. But sometimes you need to change the meaning vis value. So vis has three kinds of value and that three different meanings

vis = 0, it indicates that the vertex is not being accessed is not

vis = 1, it indicates that the vertex has already been visited, but it has not been accessed for future generations finished, but also from the point of no return

vis = 2, it indicates that the vertex has been accessed, its access to future generations has finished, has returned from the vertex

Vis three kinds of values ​​can be represented by a sequential relationship and temporal relationships.

DFS process, for an edge u-> v

vis [v] = 0, v description has not been accessed, v is first discovered, u-> v is a side of the tree , also known as branch side

vis [v] = 1, v description has been accessed, but their descendants have not been accessed End (it is available), while u and v point? Description u v is the future generations, u-> v is a backward edge , so the backward side, also known as atavistic side

vis [v] = 2, v description has been accessed, access to all of its descendants has finished, u-> v edges which may be a lateral edge of the fork , or the forward edges

1. connectivity undirected graph

Unicom: Two exists a path connecting them.

Unicom blocks: a point inside twenty-two Unicom.

Bridge: For a Unicom undirected graph, an edge is a bridge if and only if this edge after removing the communication becomes FIG.

Strongly connected components: the block is not Unicom bridge.

(Also called non-edge component of the double link graph strongly connected component, the concept corresponds to:

Communicating by double: double cut connected component is no point

For a particular subject will seek operation of the dual communication component. )

tarjan algorithm sentenced Bridge:

DFN [x] is dfs sequence x represents what number to search.

instack [x] indicates whether the current point in the stack dfs, is used to determine whether the throwback edge code if (instack [y]) which represents the point x of y subtree.

However undirected graph Unicom component instack arrays are unnecessary.

Since no two-way all edges to the graph, the forward edge of the case does not update the low (tarjan used if (instack [y]) to the front edge special sentence out without update) does not make sense (to prove: if one exists before the edge u-> v, then there is also v-> u, so when dfs has been updated to v v. again when dfs to v, if not update did not make sense) so

low [x] PPT: x side by a non-reversion, and up to the minimum by a non-tree edge dfn can reach.

I understand: x up by a non-tree edge (ie not return to his father's atavistic side) Minimum dfn can reach.

Hong teacher to define the feeling atavistic side of a mistake (mixed): the one hand literally thought it was a return to his father's side, on the other hand code using a instack correct judgment, resulting in no real sentenced to return to his father's side.

void tarjan(int x,int fa) {
    instack[x] = 1;
    dfn[x] = low[x] = ++tot;
    for (auto y : E[x]) {
        if (!dfn[y]) {
            tarjan(y,x);
            low[x] = min(low[x], low[y]);
        }
        else {
            if(y!=fa&&instack[y])low[x] = min(low[x], dfn[y]);
        }
    }
    instack[x] = 0;
}
//-----ppt中的错误代码,没有特判掉指向父亲的返祖边--------------
void tarjan(int x) {
    instack[x] = 1;
    dfn[x] = low[x] = ++tot;
    for (auto y : E[x]) {
        if (!dfn[y]) {//树边
            tarjan(y);
            low[x] = min(low[x], low[y]);
        }
        else {
            if(instack[y])low[x] = min(low[x], dfn[y]);//返祖边,一般指向父亲
        }
    }
    instack[x] = 0;
}

Bridge sentence: low [x] <dfn [x] indicates the presence of a reversion to the return side of a point above the father of y, y has a path to the x, x to y has another path. (Forming a double connected component ??)

Conversely low [x]> = dfn [x] is representative of the bridge which is connected to the father's side

2. FIG connectivity to the

Strongly connected components: any two points can reach each other.

In doing Tarjan algorithm, if Tarjan (x) after the discovery of dfn [x] == low [x], x is the submenus tree ⾥ all remaining points constituting ⼀ a strongly connected component, can be used to maintain a stack:

stack<int> S;
void tarjan(int x) {
    S.push(x);
    instack[x] = 1;
    dfn[x] = low[x] = ++tot;
    for (auto y : E[x]) {
        if (!dfn[y]) {
            tarjan(y, x);
            low[x] = min(low[x], low[y]);
        }
        else {
            if ( instack[y])low[x] = min(low[x], dfn[y]);
        }
    }
    if (low[x] == dfn[x]) {
        while (1) {
            int now = S.top();
            S.pop();
            instack[x] = 0;//把之前没有清零的一次性更新。
            /*
                染色,统计之类的操作
            */
            if (now == x)break;
        }
    }
    
}

3. examples

0.

Meaning of the questions:

Face of N, you integer M (a, b), represents a very powerful Face that b, ⽽ transitivity relationship, that is, if a powerful b, c and b that much, then a c much thought

How many are seeking Face Face all feel very badly

N,M<=10^5

practice:

Acyclic: directed graph acyclic - at least one point of the edge is not> . So look for any point, until you come to a point of no sides, sentenced to see if all the points are connected to it.

A ring: a ring for such post, as will be strongly connected, acyclic condensation point into the case (will be more multiple edges).

Routine: a title to do well in the absence of the ring (a topology), it is considered shrink ring.

1.POJ1236

Meaning of the questions:

Given a directed graph, N points, requirements:

1) To elect at least a few vertices in order to achieve from these vertices, you can reach all vertices

2) at least to increase the number of edges in order to make any departure from a vertex, you can reach all vertices

Ideas :

According to routine, Tarjan algorithm for SCC, and reduced point built FIG. So for Question 1, the new figure for the number of points 0:00 into the degree, that is the answer.

For question 2, the answer is max (the number of points of the point 0, the 0 degree point), because for every degree or out-degree of the 0-point, it is necessary to solve even an edge, then the degree of even to the point of 0 degrees to the point 0 is optimal.

In addition, if the last SCC only one, then the answer to question 2 should be special sentenced to 0.

Routine: There are methods to FIG component configured Unicom: the degree of a 0 is connected to the point of a directed graph on the 0 point.

The method of FIG Unicom undirected configuration components: interconnecting degree point (leaf) 1.

2.POJ3177

The meaning of problems: there are n ranch, Bessie from one pasture to another pasture, requires at least two separate paths to take. M is now way, at least seeking new number of routes, such that there are at least two independent paths between any two pastures. It refers to two separate paths: path no common edge, but through the same intermediate vertex. Figure assurance has been given by China Unicom.

Ideas:

At the same side of a dual-component communication (i.e. no strongly connected components of the edge), any two points has at least two independent paths can reach, so all points the same connected component in the double-side can be seen as a single point.

After the routine point reduction, new map is a tree, because the picture has been Unicom. Now is added to the tree side, so that all points of condensing a bis Unicom component side.

Even then leaves the routine, the answer is (for the tree of points 1 +1) / 2.

3. HDU3394

Meaning of the questions: There are spots a park with n, m administrator park plans to build roads, and arranged for some of the tour route forms a loop. If the road is a public road and more, then this road is conflict; if one is not in any way a loop, then this road is no conflict. Ask how many paths there are conflicts and there is no way conflicts are

Ideas:

First, non-unwanted side is obviously the bridge, because it is not in any circuit.

Then the conflict side edge is a plurality of common circuits, attention here is a simple loop circuit, the condensing point considered point BCC FIG construction, if a point BCC is greater than the number of edges in the points that at least two rings, wherein all side are conflict sides. If the number of points equal to the number of edges, then only one big ring, no conflict is changing, and in the case of BCC point less than the number of sides of points does not exist.

Guess you like

Origin www.cnblogs.com/SuuT/p/11247343.html