These days have been doing strong connectivity, and now summarize a little under
1. Definition
In an undirected graph, if any of the two points are mutually accessible, it is said that the graph is strongly connected, and the strongly connected graph of the graph, called the strong connected component
2. The method of seeking
Learn the Tarjan algorithm on white books.
Time stamp for DFS was used
Assuming a strongly connected component, C, where the first point is P, then Dfs goes down, it must be able to find a k point, return P Point, the point on this DFS path is in this strongly connected component C
If node V is found at the same time, the node v can only reach node u, then the node U is the node that the strongly connected component is first discovered.
This translates into the D-value of the ancestors who can reach the farthest point U.
So to define a low[] array is the value of the pre[v] of the first ancestor that the node u can trace back to, Pre[v] is the timestamp of node V
voidDfsintu) {Low[u]= Pre[u] = + +Dfs_clock; S.push (U); for(inti = First[u];~i;i =E[i].next) { intv =e[i].v; if(!pre[v]) {//child nodes have not been searched, then search, back to update the low valueDfs (v); Low[u]=min (low[u],low[v]); } Else if(!sc[v]) low[u] = min (low[u],pre[v]);//If the current node is not part of another SCC and has been accessed, it is the ancestor node of the current node and is updated directly with its low } if(Pre[u] = =Low[u]) {SCNT++; for(;;) { intx =S.top (); S.pop (); SC[X]=scnt; //scn[scnt]++; Here you can count the number of points in a connected component, or, when the point is a bit of power, calculate the weight of the connected component. if(x = = u) Break; } }}voidFIND_SCC () { while(!S.empty ()) S.pop (); SCNT= Dfs_clock =0; memset (Low,0,sizeof(low)); memset (PRE,0,sizeof(pre)); Memset (SC,0,sizeof(SC)); memset (SCN,0,sizeof(SCN)); for(inti =1; I <= n;i++)if(!Pre[i]) DFS (i);}
3. Some of the topics that are now done
Now do the topic is quite limited, to do their own summary under the---later met
(1) Judging whether it is a strong connected graph
1) direct to a directed graph, judging is not strong connectivity
HDU 1269
2) attaching a little limit to the
Add a limit the number of nodes in this strongly connected component is greater than 1, and the Tarjan algorithm directly counts the number
POJ 3180
(2) in relation to the degree of penetration
1) Add several edges to make the whole graph strong and connected
Petition the first example of a strong connection there
Tarjan First, find all the strong connected components
And then shrink the point,
The degree of re-entry, the degree,
The other in the degree of 0 has a C1, out of 0 has C2, max (C1,C2) is required
La 4287
HDU 2767
HDU 3836
These three are the same.
2) from which point to start, so that all points can go to
The indentation, all the degrees after the indentation is 0 is required
Hdu 1827 a connected block with a 0 degree of entry, plus a weighted value
POJ 1236 Max (C1,C2), and the number of connected components with an output degree of 0
POJ 2553 statistics out of 0 blocks
POJ 2186 Find a few points are can be reached at other points, the statistics of the number of blocks of 0 C,
Note that in the case of C > 1, the points in the block with a degree of 0 are not able to reach each other and should output 0
POJ 2375 Convert the graph to max (C1,C2)
(3) and other combinations of
It is generally necessary to use a shrinking point, after which a directed acyclic graph is formed to form a dag,
We can DP,DFS,SPFA.
UVA 11324
First find out all the strong connectivity, and then shrink the point, after the end of the set up a new diagram
The way to build the map is to sweep all the edges, if you find that the edge of the two endpoints u,v in different connected components, in the sc[u],sc[v] between a side
is transformed into the path that maximizes the power of the DAG.
There's another way to do that.
Add a source point to go in, and the point of the source and the point after the indentation of all the points of 0 connected to an edge
And then spfa the path of finding the most right
POJ 3160 is the same as this question.
POJ 2762-point topology sort after indent
POJ 3114 after the Dijkstra, with Floyd will be t off
POJ 3592 diagram after conversion, SPFA
Do these----now.
Read these two blogs to do the topic---
http://blog.csdn.net/accelerator_/article/details/40349411
http://blog.csdn.net/u013013910/article/category/2509879
Book---strong connected components