Transmission Door
One of the three applications of Tarjan: Solving the dual-link component of a point.
Solves the point double Unicom component. Then the pinch point, differential optimization can be.
Bzoj 3331//by cydiater//2016.10.29#include <iostream> #include <cmath> #include <cstdlib> #include <cstdio> #include <queue> #include <map> #include <cstring> #include <string> #include <algorithm> #include <set> #include <bitset> #include <iomanip> #include <ctime> #include <vector>using namespace std; #define LL Long long#define up (i,j,n) for (int. i=j;i<=n;i++) #define DOWN (i,j,n) for ( int i=j;i>=n;i--) #define CMAX (A, B) A=max (A, b) #define Cmin (A, B) A=min (A, b) #define Auto (i,a) for (int i=link[a];i;i=e[ I].next) #define VCI vector<int> #define PB push_backconst int maxn=4e5+5;const int oo=0x3f3f3f3f;inline int read () { Char Ch=getchar (); int x=0,f=1;while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int N,m,q,lable[maxn],dfn[maxn],low[maxn],stack[maxn],top=0,dfs_clock=0,fa[maxn][25],dep[maxn],group_num=0;vci Group[maxn];struct edge{int x,y,next;}; struct Graph{int Link[maxn],len; Graph () {memset link,0,sizeof (LINK); len=0;} Edge e[maxn];inline void Insert (int x,int y) {e[++len].next=link[x]; Link[x]=len;e[len].y=y;e[len].x=x;} inline void Insert (int x,int y) {insert (x, y); insert (y,x);} void Tarjan (int node) {Dfn[node]=low[node]=++dfs_clock;stack[++top]=node;int son=0; Auto (I,node) if (!dfn[e[i].y]) {Tarjan (E[I].Y); Cmin (Low[node],low[e[i].y]); if (Low[e[i].y]>=dfn[node]) {int tmp; group_num++;d O{TMP=STACK[TOP--];GROUP[GROUP_NUM].PB (TMP);} while (TMP!=E[I].Y); GROUP[GROUP_NUM].PB (node);}} else Cmin (Low[node],dfn[e[i].y]);} void Dfs (int node,int deep,int father) {fa[node][0]=father;dep[node]=deep; Auto (I,node) if (e[i].y!=father) DFS (e[i].y,deep+1,node);} void Get_ancestor () {Up (i,1,20) up (Node,1,n+group_num) if (fa[node][i-1]) fa[node][i]=fa[fa[node][i-1]][i-1];} int LCA (int x,int y) {if (x==y) return x;if (Dep[x]<dep[y]) swap (x, y);d Own (i,20,0) if (dep[x]-(1<<i) >=dep[y]) X=fa[x][i];if (x==y) return X;down (i,20,0) if (fa[x][i]!=0&&fa[x][i]!=fa[y][i]) {x=fa[x][i];y=fa[y][i];} return fa[x][0];} void Re_dfs (int node) {Auto (I,node) if (E[i].y!=fa[node][0]) {Re_dfs (E[I].Y); lable[node]+=lable[e[i].y];}}} G1,g2;namespace solution{void init () {n=read (); M=read (); Q=read (); up (i,1,m) {int x=read (), Y=read (); G1. Insert (x, y);}} void Slove () {G1.tarjan (1); up (I,1,group_num) up (J,0,group[i].size ()-1) G2. Insert (I+n,group[i][j]); G2.dfs (1,0,0); G2.get_ancestor (); memset (Lable,0,sizeof (lable)), while (q--) {int x=read (), Y=read (), Lca=g2. LCA (x, y); lable[x]++;lable[y]++;lable[lca]--;lable[fa[lca][0]]--;} G2.re_dfs (1);} void output () {Up (i,1,n) printf ("%d\n", Lable[i]);}} int main () {//freopen ("input.in", "R", stdin), using namespace Solution;init (); slove (); output (); return 0;}
BZOJ3331: [BeiJing2013] Pressure