Poj transferring Sylla (how to quickly determine whether a graph is a 3-connected graph, find the cut point and cut edge)

Source: Internet
Author: User

Transferring Sylla

 

First, what is a K-connected graph? A k-connected graph is a graph with at least K points removed for non-connectivity.

Question:

The topic description is very bare, that is, to give you a graph that requires you to determine whether the graph is a 3-connected graph.

 

Algorithm analysis:

//////////////////////////////////////// /////////////////////////////

(The analysis by others on the Internet is very good, so it is directly referenced)

Consider the unfeasible situation, that is, there is a number of path entries between two points <3, then we can enumerate two vertices A and B, and then delete them and adjacent edges, determine the number of connected blocks. If the number of connected blocks is greater than 1, the number of path entries is less than 3; otherwise, the number does not exist, because if a and B are the points on the path where the number of path entries is <3, if they are broken, these two points will not be connected again, because it is not feasible, the maximum number of paths is 2, so you only need to enumerate two points.

//////////////////////////////////////// /////////////////////////////////

But this definitely times out!

Therefore, we need to optimize it. We can think that since the enumeration of two points will time out, now I only enumerate one point? Of course.

But why can we enumerate only one vertex? Because we can know from the cut point definition that when a graph is a strongly connected graph, it must not be cut. Therefore, when we enumerate the deleted vertex, if there is a cut vertex in the remaining graph, this graph must not be a 3-connected graph. Because, in this case, we only need to delete the two sides so that they cannot be connected.

 

A cut-point and cut-edge template is provided. You only need a set of templates for this question.

/// // Data // vector <int> G [maxn]; int V, E; bool cut [maxn]; // whether it is a cut point int color [maxn]; // 0: no access 1: Access 2: you have accessed int lowc [maxn]; // It indicates the depth of int d [maxn] Where the ancestor nodes with the highest generation are connected to the descendants of I and I. // indicates the depth of the I node in the tree int root; // The root node int Fath; // The parent node int PCNT; // The number of cut points int egcnt; // bool flag; // indicates whether a cut point exists. ///date end /////////////////// ////// initialize void Init () {flag = false; For (INT I = 0; I <= V; ++ I) g [I]. clear ();} //// // Tarjan ////////////////////// void DFS (int u, int FA, int deep) {color [u] = 1; // accessing lowc [u] = d [u] = deep; // depth int tot = 0; // Number of subtree int I, V; for (I = 0; I <(INT) g [u]. size (); ++ I) {v = G [u] [I]; If (V! = Fa & Color [v] = 1) {lowc [u] = min (lowc [u], d [v]);} if (0 = color [v]) {DFS (v, U, deep + 1); Tot ++; // subtree + 1 lowc [u] = min (lowc [u], lowc [v]); // find the cut point if (u = root & tot> 1) | (u! = Root & lowc [v]> = d [u]) {cut [u] = 1; // do not write PCNT ++ here flag = true ;} /* // find the cut edge U-> V is the cut edge if (lowc [v]> d [u]) {edge [u] [v] = true ;} */} color [u] = 2 ;} //// // end Tarjan // void calc (INT del) {PCNT = egcnt = 0; memset (CUT, 0, sizeof (CUT); memset (color, 0, sizeof (color); memset (lowc, 0, sizeof (lowc); memset (D, 0, sizeof (d); color [del] = 2; root = 0; If (DEL = 0) root = 1; DFS (root,-); // counts the number of cut points for (INT I = 0; I <v; ++ I) if (cut [I]) PCNT ++; * // determine whether the graph is a three-connected void solve () {for (INT I = 0; I <v; ++ I) {calc (I ); // determine whether the graph is connected to for (Int J = 0; j <v; ++ J) {If (0 = color [J]) {flag = true; break ;}} if (FLAG) Break ;}}


 

 

 

 

 

Poj transferring Sylla (how to quickly determine whether a graph is a 3-connected graph, find the cut point and cut edge)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.