## tarjan求割点

Posted by yjjr's blog on October 31, 2018

# 题目

## Sample Input

5 5
1 2
2 3
1 3
3 4
4 5


## Sample Output

8
8
16
14
8


Tarjan求割点

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+6;
int n,m,cnt=0,tim,last[maxn],size[maxn],dfn[maxn],low[maxn];
ll ans[maxn];
struct edge{int to,next;}e[maxn<<1];
void insert(int u,int v){
e[++cnt]=(edge){v,last[u]};last[u]=cnt;
e[++cnt]=(edge){u,last[v]};last[v]=cnt;
}
void tarjan(int x){
int now=0;size[x]=1;
dfn[x]=low[x]=++tim;
reg(x){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[x]=min(low[x],low[v]);
size[x]+=size[v];
if(dfn[x]<=low[v]){
ans[x]+=1ll*now*size[v];
now+=size[v];
}
}
else low[x]=min(low[x],dfn[v]);
}
ans[x]+=1ll*now*(n-now-1);
}
int main(){