BZOJ1123: [POI2008]BLO

Description

Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。

Input

输入n<=100000 m<=500000及m条边

Output

输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。

Sample Input

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

Sample Output

8
8
16
14
8
 
傻逼题我来挂个Tarjan跑割点的模板(话说BZOJ良心发现放开权限题了???)
对于每个点,如果不是割点(割掉就不联通),那么答案显然是2*(n-1)
如果是,那么割出来T个块,然后两两相乘累加即可
//MT_LI
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
    int x,y,next;
}a[2100000];int len,last[210000];
void ins(int x,int y)
{
    len++;
    a[len].x=x;a[len].y=y;
    a[len].next=last[x];last[x]=len;
}
int n,m;
ll ans[210000];
int tot[210000],cut[210000];
int low[210000],dfn[210000],cnt;
void dfs(int x)
{
    tot[x]=1;dfn[x]=low[x]=++cnt;
    int sum=0,t=0;
    for(int k=last[x];k;k=a[k].next)
    {
        int y=a[k].y;
        if(!dfn[y])
        {
            dfs(y);
            tot[x]+=tot[y];
            low[x]=min(low[x],low[y]);
            if(low[y]>=dfn[x])
            {
                t++;
                ans[x]+=(ll)tot[y]*(n-tot[y]);
                sum+=tot[y];
                if(x!=1||t>1)cut[x]=1;
            }
        }
        else low[x]=min(low[x],dfn[y]);
    }
    if(cut[x])ans[x]+=(ll)(n-sum-1)*(sum+1)+(n-1);
    else ans[x]=2*(n-1);
}
int main()
{
    scanf("%d%d",&n,&m);cnt=0;
    len=0;memset(last,0,sizeof(last));
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x!=y)ins(x,y),ins(y,x);
    }
    dfs(1);
    for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
    return 0;
}

 

转载于:https://www.cnblogs.com/MT-LI/p/9699439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值