Bzoj1123 Blockade

题目链接:https://loj.ac/problem/10104


日常水题,题目中已经给出了算法,写个模板即可,不会割点的这里有一篇博客:https://www.cnblogs.com/WWHHTT/p/9745499.html

难点是每个对可以互换顺序,然后删掉一个点之后它与其他所有点的对都会少1

下面给出代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
inline int rd(){
    int x=0,f=1;
    char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
    return x*f;
}
inline void write(long long x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    return ;
}
int n,m;
int head[1000006],nxt[1000006],to[1000006];
int total=0;
void add(int x,int y){
    total++;
    to[total]=y;
    nxt[total]=head[x];
    head[x]=total;
    return ;
}
int tot=0;
int dfn[1000006],low[1000006],book[1000006];
int q[1000006],l=0,r=0;
int size[1000006];
long long ans[1000006];
void Tarjan(int x){
    int sum=0;
    size[x]=1;
    dfn[x]=low[x]=++tot;
    for(int e=head[x];e;e=nxt[e]){
        if(!dfn[to[e]]){
            Tarjan(to[e]);
            low[x]=min(low[x],low[to[e]]);
            size[x]+=size[to[e]];
            if(low[to[e]]>=dfn[x]){
                ans[x]+=(long long)sum*(long long)size[to[e]];
                sum+=size[to[e]];
            }
        }
        else low[x]=min(low[x],dfn[to[e]]);
    }
    ans[x]+=(long long)sum*(long long)(n-sum-1);
    return ;
}
int main(){
    n=rd(),m=rd();
    for(int i=1;i<=m;i++){
        int x=rd(),y=rd();
        add(x,y),add(y,x);
    }
    for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i);
    for(int i=1;i<=n;i++) write((ans[i]+n-1)*2),puts("");
    return 0;
}

 

转载于:https://www.cnblogs.com/WWHHTT/p/9832540.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值