[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用点双,求出哪些点是割点,然后就是自己的所有子树大小相乘,还有父亲的那一块区域。最后要加上n-1,有序的话再乘个2就好

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar())  if (ch=='-')    f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar())    x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
inline void print(int x){
    if (x>=10)     print(x/10);
    putchar(x%10+'0');
}
const int N=1e5,M=5e5;
int pre[(M<<1)+10],now[N+10],child[(M<<1)+10];
int dfn[N+10],low[N+10],size[N+10];
ll Ans[N+10];
int Time,n,m,tot;
void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
void tarjan(int x){
    int T=0;
    size[x]=1;
    dfn[x]=low[x]=++Time;
    for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
        if (!dfn[son]){
            tarjan(son);
            size[x]+=size[son];
            low[x]=min(low[x],low[son]);
            if (dfn[x]<=low[son]){
                Ans[x]+=1ll*T*size[son];
                T+=size[son];
            }
        }else   low[x]=min(low[x],dfn[son]);
    }
    Ans[x]+=1ll*T*(n-T-1);
}
int main(){
    n=read(),m=read();
    for (int i=1;i<=m;i++){
        int x=read(),y=read();
        join(x,y),join(y,x);
    }
    tarjan(1);
    for (int i=1;i<=n;i++)  printf("%lld\n",(Ans[i]+n-1)<<1);
    return 0;
}

转载于:https://www.cnblogs.com/Wolfycz/p/9034943.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值