首页 > 其他 > 详细

BZOJ1123: [POI2008]BLO

时间:2018-09-25 15:09:18      阅读:127      评论:0      收藏:0      [点我收藏+]

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;
}

 

BZOJ1123: [POI2008]BLO

原文:https://www.cnblogs.com/MT-LI/p/9699439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!