Data structure learning (C ++) - Figure [3] (no map) (on)

zhaozj2021-02-16  67

If it is placed casually on the paper, or only the exemplary explanation of the graph, most people choose no way. However, in the computer, the non-map of the map is stored in the direction of the map-stored side. In fact, when we say that there is no trend, just ignore the direction - draw a line on the paper, it is difficult to come into the line "嗖", is not from one head to another?

There are several unique concepts, connectivity components, joint points, and minimal flowers. The following will be described, before this, the basic operation of the non-map class is completed before this.

Non-map class

Template

Class Graph: Public Network

{

PUBLIC:

Graph () {}

Graph (dist MaxDist): Network (maxdist) {}

Bool Inserte (Name V1, Name V2, DIST COST)

{

IF (Network :: Inserte (V1, V2, COST))

Return NetWork :: Inserte (V2, V1, COST);

Return False;

}

}

Just adding a side, add a reverse side, very simple.

Communication component

This is unique, there is a direction to complicate more (strong, single, weak communication), the reason is how to go without the direction, there is a direction of the picture, there is no abyss I can't climb it. With DFS, the algorithm for seeking connection components becomes very simple - you can call DFS for each vertex that has not accessed.

Void Components ()

{

Visited = new bool [vnum ()]; INT i, j = 0;

For (i = 0; i

Cout << "Components:" << Endl;

For (i = 0; i

{

IF (! Visited [i]) {cout << '(' << j << ')'; DFS (i); cout << endl;}

}

DELETE [] Visited;

}

The part of the black body is the core.

Junction

Defining is a way to know things, because the concept makes people distinguish things - about this absolute movement and relative stationary philosophical perspective (the river is always in flow, but the Yangtze River is also called the Yangtze River, remember that famous "Is it impossible to step into the same river"?) So, can there be an accurate concept is often a sign of a discipline development, and whether the next accurate definition reflects a person's thinking ability. Said so many nonsense, only one, I didn't figure out what is "joint point" - the reference book is limited, can not be carefully selected, if there is misunderstanding, I hope to correct.

Strict version saying: If a vertex is deleted, a connected component of the figure is divided into two or more connected components, saying the vertex is a joint point. - Although not mentioned that the picture must be no trend, it is mentioned that the connection component has been default is no map.

Yin Edition said that: in a non-contrast chart, ... (Yu Shi Yan Edition).

The problem came out, can the non-connected map can discuss related nodes? Can we say that a connection component contains relevant nodes? Unfortunately, after the strict version leaves this problem, the algorithm given later is given in accordance with the communication map, so that the result is wrong when the figure is not connected. Yin version is a slider, only outputs the re-connect component, does not output the joint point, although it is assumed that the picture is connected, it is also not connected. Turning over the discrete mathematics, the result is not found "Joint Point", only "cutting point", is this: a non-portable chart, if you delete a vertex, become a non-connected map, the vertex is called the cut point . The right to "cut the point" is "joint point", then the algorithm should at least first judge whether it is connected? However, it is directly connected to the book ...

About the algorithm is no longer thin, there are books. The following example can output the "joint point" of each connectivity component (can be called like this, I don't know). The DFN stores the access serial number of each vertex, and the LOW is a depth priority to generate a child of each non-leaf vertex to a minimum access sequence number that can be reached by back. The side pointing to the double-minded side does not affect the judgment, so there is no need to distinguish it, and the Yin version explicitly distinguishes, belongs to the snake. In this way, if (low [n]> = dfn [i]) cout << Getv (i); this output joint point is very embarrassing in the judgment of the output joint point, because only can only be equal to impossible. It is also important to note that the root of the tree (starting point of DFS) is separately judged.

void articul ()

{

DFN = new int [vnum ()]; low = new int [vnum ()]; int i, j = 0, n;

For (i = 0; i

For (i = 0; i

{

IF (! DFN [i])

{

Cout << '(' << j << ')'; DFN [I] = Low [i] = count = 1;

IF ((n = nextv (i))! = -1) articul (n); bool out = false; // Access Tree Root

While ((n = nextv (i, n)))! = -1)

{

IF (DFN [N]) Continue;

If (! out) {cout << getv (i); out = true;} // tree roots have not only one child

Articul (n); // Access other children

}

Cout << Endl;

}

}

DELETE [] DFN; Delete [] Low;

}

Private:

Void Articul (INT i)

{

DFN [I] = low [i] = count;

For (int N = nextv (i); n! = -1; n = nextv (i, n)))

{

IF (! dfn [n])

{

Articul (n);

IF (Low [n]

IF (low [n]> = DFN [i]) cout << getv (i); // Here only possible =

}

ELSE IF (DFN [N]

}

}

INT * DFN, * LOW, COUNT

转载请注明原文地址:https://www.9cbs.com/read-22969.html

New Post(0)