2018.09.15[POI2008]BLO-Blockade(割点)

8 篇文章 0 订阅
2 篇文章 0 订阅
描述

There are exactly nn towns in Byteotia.
Some towns are connected by bidirectional roads.
There are no crossroads outside towns, though there may be bridges, tunnels and flyovers. Each pair of towns may be connected by at most one direct road. One can get from any town to any other-directly or indirectly.
Each town has exactly one citizen.
For that reason the citizens suffer from loneliness.
It turns out that each citizen would like to pay a visit to every other citizen (in his host’s hometown), and do it exactly once. So exactly n\cdot (n-1)n⋅(n−1) visits should take place.
That’s right, should.
Unfortunately, a general strike of programmers, who demand an emergency purchase of software, is under way.
As an act of protest, the programmers plan to block one town of Byteotia, preventing entering it, leaving it, and even passing through.
As we speak, they are debating which town to choose so that the consequences are most severe.
Task Write a programme that:
reads the Byteotian road system’s description from the standard input, for each town determines, how many visits could take place if this town were not blocked by programmers, writes out the outcome to the standard output.
给定一张无向图,求每个点被封锁之后有多少个有序点对(x,y)(x!=y,1<=x,y<=n)满足x无法到达y

输入

In the first line of the standard input there are two positive integers: n and m (1n100000,1m500000) ( 1 ≤ n ≤ 100 000 , 1 ≤ m ≤ 500 000 ) denoting the number of towns and roads, respectively.
The towns are numbered from 1 to nn .
The following mm lines contain descriptions of the roads.
Each line contains two integers a and b ( 1a<bn 1 ≤ a < b ≤ n ) and denotes a direct road between towns numbered a and b

输出

Your programme should write out exactly nn integers to the standard output, one number per line. The i^{th}i th line should contain the number of visits that could not take place if the programmers blocked the town no. i .

样例输入

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

样例输出

8
8
16
14
8


这是很早之前一次模拟赛的签到题(当时数组开小了80分233)
如今又遇到这道题心里直呼缘分。
其实就是tarjan求割点一下统计答案就行了。
代码:

#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000005
using namespace std;
inline int read(){
    int ans=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
    return ans;
}
inline void write(ll x){
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int cnt=0,first[N],n,m,dfn[N],low[N],tot=0,rt;
ll siz[N],d[N];
bool vis[N];
struct Node{int v,next;}e[M];
inline void add(int u,int v){e[++cnt].v=v,e[cnt].next=first[u],first[u]=cnt;}
inline void tarjan(int p){
    vis[p]=true;
    dfn[p]=low[p]=++tot;
    siz[p]=1;
    int ch=0;
    ll tmp=0,th=1;
    bool f=false;
    for(int i=first[p];i;i=e[i].next){
        int v=e[i].v;
        if(!dfn[v]){
            ++ch;
            tarjan(v);
            if(low[v]>=dfn[p]){
                f=true;
                tmp+=(n-1-siz[v])*siz[v];
                th+=siz[v];
            }
            siz[p]+=siz[v];
            low[p]=min(low[p],low[v]);
        }
        else if(vis[v])low[p]=min(low[p],dfn[v]);
    }
    tmp+=(n-th)*(th-1);
    if(p==1&&ch<2)f=false;
    d[p]=f?tmp:0;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=m;++i){
        int u=read(),v=read();
        add(u,v),add(v,u);
    }
    tarjan(1);
    for(int i=1;i<=n;++i)write(d[i]+2*n-2),puts("");
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值