luogu P3469

Topic Link

The meaning of problems

Unicom a undirected graph, each point inquiry after deleting the point, how many points would have been to China Unicom, not connected now.

data range

Points 1 e 5 \le 1e5 , the number of edges 5 e 5 \ The 5E5

solution

Board cut point questions:

First of all can be found only cut point will cause additional changes in the connectivity of certain points, so calculated cut point while seeking contributions.
Is recorded at each point in the sub-tree size dfs tree, then if it is cut point, put the each son's sub-tree nodes point ride together, finally, + n-1, and represent all points of the point of no longer Unicom.

#include<cstdio>
#include<cstring>
inline int min(int a,int b)
{
	return a<b?a:b;
}
int n,m,cnt,h[100005],v[1000005],p[1000005];
void add(int a,int b)
{
	p[++cnt]=h[a];
	v[cnt]=b;
	h[a]=cnt;
}
int dfn[100005],low[100005],tim;
long long vis[100005],flag[100005];
void tarjan(int now)
{
	dfn[now]=low[now]=++tim;
	vis[now]=1;
	long long z=0;
	for(int i=h[now];i;i=p[i])
	{
		int v1=v[i];
		if(!dfn[v1])
		{
			tarjan(v1);
			low[now]=min(low[v1],low[now]);
			vis[now]+=vis[v1];
			if(dfn[now]<=low[v1])
			{
				flag[now]+=z*vis[v1];//割点的额外贡献
				z+=vis[v1];
			}
		}
		else low[now]=min(low[now],dfn[v1]);
	}
	flag[now]+=z*(n-z-1);//如果当前点是割点,那么dfs树中当前点子树外的点和子树内的点都不再联通
}
int main()
{
	scanf("%d %d",&n,&m);
	int a,b;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&a,&b);
		add(a,b);
		add(b,a);
	}
	tarjan(1);
	for(int i=1;i<=n;i++)
	{		
		printf("%lld\n",(flag[i]+n-1));
	}
	return 0;
}

Published 62 original articles · won praise 1 · views 987

Guess you like

Origin blog.csdn.net/wmhtxdy/article/details/103873547