#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int N = 1e5, M = 1e5;st ruct Edge {int V, next, IDX; Edge () {} edge (int _v, int _next, int _idx): V (_v), Next (_next), idx (_IDX) {}}e[m];int dfn[n], deep, head[n], tot; BOOL Iscut[n], isbri[m];void __init__ () {tot = deep = 0; Memset (Head,-1, sizeof (head)); memset (DFN, 0, sizeof (DFN)); memset (iscut, 0, sizeof (iscut)); memset (Isbri, 0, sizeof (Isbri));} void Add (int u, int v, int idx) {E[tot] = Edge (V, Head[u], IDX); Head[u] = tot++;} The DFN value of the earliest ancestor that Lowi:i and its descendants can walk through the back edge int dfs (int u, int fa) {int Lowu = Dfn[u] = ++deep;//timestamp and initialize low value int son = 0;//son number is 0 for (int i = head[u]; ~i; i = e[i].next) {int v = E[I].V; if (!dfn[v]) {//The next point points to son son++; int LOWV = DFS (v, u); Lowu = min (Lowu, LOWV); if (LOWV >= dfn[u]) iscut[u] = 1;//has no back edge, is the joint point if (Lowv > Dfn[u]) isbri[e[i].idx] = true; } else if (Dfn[v] < Dfn[u] && v! = FA)//point to Grandpa, find back side Lowu = Min (Lowu, dfn[v]);//Use Back edge to update low value} if (FA = =-1 && son = = 1) iscut[u] = 0;//only one son's root node is not the top of the cut return LOWU;} int main () {__init__ (); return 0;}
"Joint point + Bridge" joint point and Bridge template Tarjan