I really pig brain wow
Sister school is all about is I ate
moment
Today I review a bit, think it is better to write it down
After all, my memory
Like the winter wind
Not only brush brush also blow whiz
About a cut point and cutting edge (Bridge):
Cutpoint : FIG puncturing it and even to become non-communication side after
Can become a point of cutting conditions : 1. For the root node, there are two or more sub-tree 2. For non-root non-leaf nodes of a subtree does not point back to the edge of the ancestors of u
Cutting edge : Deletion After this edge becomes not communicate FIG.
Cutting edge condition becomes : (u, v) and the side of the tree when low [v]> dfn [u ] Reason: v represents only nodes connected by this edge and u
Example: Luo Gu P3388 [template] point cut (top cut)
Code:
#include <iostream> #include <cstdio> #include <cstring> #define N 100010 using namespace std; struct node { int next, to; }e[N * 2]; int n, m, idx, cnt, tot; int head[N], dfn[N], low[N]; bool cut[N]; void add (int x, int y) { e[++cnt].next = y; e[cnt].to = head[x]; head[x] = cnt; } void tarjan (int u, int fa) { dfn[u] = low[u] = ++idx; int child = 0; for (int i = head[u]; i; i = e[i].to) { int nx = e[i].next; if (!dfn[nx]) { tarjan (nx, fa); low[u] = min (low[u], low[nx]); if (low[nx] >= dfn[u] && u != fa) cut[u] = 1; if (u == fa) child++; } else low[u] = min (low[u], dfn[nx]); } if (child >= 2 && u == fa) cut[u] = 1; } int main () { scanf ("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int a, b; scanf ("%d%d", &a, &b); add (a ,b); add (b, a); } for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan (i, i); for (int i = 1; i <= n; i++) if (cut[i]) tot++; printf ("%d\n", tot); for (int i = 1; i <= n; i++) if (cut[i]) printf ("%d ", i); return 0; }
About strongly connected components:
Strong maximum Unicom subgraph not strongly connected graph (lian through which matter)
To use the stack
example: