[Graph Theory] dual-connection Summary

Source: Internet
Author: User
Dual connection Summary

Such problems are divided into edge-Dual-connection and point-Dual-connection.

EDGE connection

After the edge is dual-connected, the component that does not have a dual-connected connection is the cut edge. Therefore, you can reduce the node into a tree and convert the problem into a tree. The cut edge is defined: after this edge is removed, the graph will not be connected.

Basically, each of these questions has a solution, which is to calculate the dual-connected component and then scale down the vertex into a tree for operations.
Or, you can directly request the edge to be cut and perform operations related to the edge.

Template:

# Include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> # include <vector> using namespace STD; const int n = 10005; const int M = 20005; int n, m, Val [N]; struct edge {int U, V, ID; bool iscut; edge () {} edge (int u, int V, int ID) {This-> U = u; this-> V = V; this-> id = ID; this-> iscut = false ;}} edge [M * 2], cut [m]; int en, first [N], next [m], cutn; void Init () {memset (first,-1, sizeof (first); e N = 0;} void add_edge (int u, int V, int ID) {edge [En] = edge (u, v, ID ); next [En] = first [u]; first [u] = EN ++;} int pre [N], dfn [N], bccno [N], BCCN, dfs_clock; void dfs_cut (int u, int FA) {pre [u] = dfn [u] = ++ dfs_clock; For (INT I = first [u]; I + 1; I = next [I]) {int v = edge [I]. v; If (edge [I]. id = FA) continue; If (! Pre [v]) {dfs_cut (v, edge [I]. ID); dfn [u] = min (dfn [u], dfn [v]); If (dfn [v]> pre [u]) {edge [I]. iscut = edge [I ^ 1]. iscut = true; // mark the cut edge cut [cutn ++] = edge [I]; // save cut edge} else dfn [u] = min (dfn [u], pre [v]);} void find_cut () {dfs_clock = cutn = 0; memset (PRE, 0, sizeof (pre); For (INT I = 0; I <n; I ++) if (! Pre [I]) dfs_cut (I,-1);} void dfs_bcc (INT U) {pre [u] = 1; bccno [u] = BCCN; for (INT I = first [u]; I + 1; I = next [I]) {If (edge [I]. iscut) continue; int v = edge [I]. v; If (pre [v]) continue; dfs_bcc (v) ;}} vector <int> BCC [N]; void find_bcc () {BCCN = 0; memset (PRE, 0, sizeof (pre); For (INT I = 0; I <n; I ++) {If (! Pre [I]) {dfs_bcc (I); BCCN ++ ;}} int main () {return 0 ;}

HDU 2242 road to postgraduate entrance-air-conditioning classrooms with dual-connection deflation points + DFS
HDU 2460 Network side dual-connection deflation point + tree link splitting
HDU 3849by recognizing these guys, we find social networks useful bridge
HDU 4005 the war side dual-connection deflation point + DFS
HDU 3394 railway dual-connection Block
3177 redundant paths constructs edge dual-connectivity and uses the degree to calculate
3352 Road Construction
1515 street directions can be changed to an undirected graph, and the bridge cannot be changed.
1438 one-way traffic hybrid graph change directed graph (the data in this question seems a bit problematic)

Point dual-connection

Point dual-connectivity, find out, connect to the cut point, note that a cut point may belong to different points-Dual-connectivity component, the cut point is defined as: After removing this point, graph will not be connected

Template:

#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <stack>using namespace std;const int N = 1005;const int M = 2000005;int n, m;struct Edge {int u, v;Edge() {}Edge(int u, int v) {this->u = u;this->v = v;}} edge[M];int first[N], next[M], en;void add_edge(int u, int v) {edge[en] = Edge(u, v);next[en] = first[u];first[u] = en++;}void init() {en = 0;memset(first, -1, sizeof(first));}int pre[N], dfn[N], bccno[N], dfs_clock, bccn;bool iscut[N];stack<Edge> S;vector<int> bcc[N];void dfs_bcc(int u, int fa) {dfn[u] = pre[u] = ++dfs_clock;int child = 0;for (int i = first[u]; i + 1; i = next[i]) {int v = edge[i].v;if (fa == v) continue;if (!pre[v]) {S.push(edge[i]);child++;dfs_bcc(v, u);dfn[u] = min(dfn[u], dfn[v]);if (dfn[v] >= pre[u]) {iscut[u] = true;bccn++;bcc[bccn].clear();while (1) {Edge x = S.top(); S.pop();if (bccno[x.u] != bccn) {bcc[bccn].push_back(x.u); bccno[x.u] = bccn;}if (bccno[x.v] != bccn) {bcc[bccn].push_back(x.v); bccno[x.v] = bccn;}if (x.u == u && x.v == v) break;}}} else if (pre[v] < pre[u] && v != fa) {S.push(edge[i]);dfn[u] = min(dfn[u], pre[v]);}}if (fa == 0 && child == 1) iscut[u] = 0;}void find_bcc() {memset(pre, 0, sizeof(pre));memset(bccno, 0, sizeof(bccno));memset(iscut, false, sizeof(iscut));dfs_clock = bccn = 0;for (int i = 1; i <= n; i++)if (!pre[i]) dfs_bcc(i, 0);}


Poj 2942 knights of the Round Table point dual-connection classic questions, using DOT dual-connection and two-dyeing to do
Ultraviolet A 1108 mining your own business point dual-Connected Component + count

[Graph Theory] dual-connection Summary

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.