[POI2008]BLO-Blockade

https://www.luogu.org/problem/show?pid=3469

题目描述

There are exactly  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 ![](http://main.edu.pl/images/OI15/blo-en-tex.2.png) 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:  and  () denoting the number of towns and roads, respectively.

The towns are numbered from 1 to .

The following  lines contain descriptions of the roads.

Each line contains two integers  and  () and denotes a direct road between towns numbered  and .

输出格式:

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

输入输出样例

输入样例#1:
5 5
1 2
2 3
1 3
3 4
4 5
输出样例#1:
8
8
16
14
8

首先,删除这个点后,剩余的n-1个点都不能与这个点连接,所以每个点至少有(n-1)*2对
如果点是割点,那么将点封锁后,会有k个连通块
它就要另外加上 每个连通块*其余连通块的和
#include<cstdio>
#include<algorithm>
#define N 100001
#define M 500001
using namespace std;
int n,m;
int front[N],to[M*2],nxt[M*2],tot=1;
int dfn[N],low[N];
bool cutpoint[N];
int fa[N],siz[N],sum[N];
long long ans[N];
void add(int u,int v)
{
    to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
    to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
}
void tarjan(int now)
{
    siz[now]++;
    low[now]=dfn[now]=++tot;
    int s=0; bool tmp=false;
    for(int i=front[now];i;i=nxt[i])
    {
        if(!dfn[to[i]])
        {
            tarjan(to[i]);
            siz[now]+=siz[to[i]];
            low[now]=min(low[now],low[to[i]]);
            if(low[to[i]]>=dfn[now])
            {
                ans[now]+=1ll*s*siz[to[i]];
                s+=siz[to[i]];
            }
        }
        else low[now]=min(low[now],dfn[to[i]]);
    }
    ans[now]+=1ll*s*(n-s-1);
}
int main()
{
    scanf("%d%d",&n,&m);
    int u,v;
    while(m--)
    {
        scanf("%d%d",&u,&v);
        add(u,v);
    }
    tot=0;
    tarjan(1);
    for(int i=1;i<=n;i++) printf("%lld
",ans[i]+n-1<<1);
}
原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/7072837.html