描述

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(1≤n≤100000,1≤m≤500000)" role="presentation" style="position: relative;">(1≤n≤100000,1≤m≤500000)(1≤n≤100000,1≤m≤500000)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 (1≤a&lt;b≤n" role="presentation" style="position: relative;">1≤a<b≤n1≤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;
}

2018.09.15[POI2008]BLO-Blockade(割点)的更多相关文章

  1. Lean Data Innovation Sharing Salon(2018.09.15)

    时间:2018.09.15地点:北京国华投资大厦

  2. 2018.09.15 poj2117Electricity(割点)

    传送门 其实求一个图删除一个点之后,联通块最多有多少. 直接tarjan求割点更新答案就行了. 但注意原图不一定连通. 代码: #include<iostream> #include< ...

  3. bzoj1123 [POI2008]BLO——求割点子树相乘

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1123 思路倒是有的,不就是个乘法原理吗,可是不会写...代码能力... 写了一堆麻麻烦烦乱七 ...

  4. 2018.09.15点名器(简单dp)

    描述 Ssoier在紧张的学习中,杜老师每天给他们传授精妙的知识. 杜老师为了活跃气氛,设计了一个点名器,这个点名器包含一个长度为M的数组(下标1开始),每个元素是一个oier的名字,每次点名的时候, ...

  5. 2018.09.15 poj1734Sightseeing trip(floyd求最小环)

    跟hdu1599差不多.. 只是需要输出方案. 这个可以递归求解. 代码: #include<iostream> #include<cstdio> #include<cs ...

  6. 2018.09.15 hdu1599find the mincost route(floyd求最小环)

    传送门 floyd求最小环的板子题目. 就是枚举两个相邻的点求最小环就行了. 代码: #include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f ...

  7. 2018.09.15 bzoj1977:次小生成树 Tree(次小生成树+树剖)

    传送门 一道比较综合的好题. 由于是求严格的次小生成树. 我们需要维护一条路径上的最小值和次小值. 其中最小值和次小值不能相同. 由于不喜欢倍增我选择了用树链剖分维护. 代码: #include< ...

  8. 2018.09.15 秘密的牛奶管道SECRET(次小生成树)

    描述 约翰叔叔希望能够廉价连接他的供水系统,但是他不希望他的竞争对手知道他选择的路线.一般这样的问题需要选择最便宜的方式,所以他决定避免这种情况而采用第二便宜的方式. 现在有W(3 <= W & ...

  9. 2018.09.15 vijos1053Easy sssp(最短路)

    传送门 貌似可以最短路时同时判定负环啊. 但我不想这样做. 于是写了一个dfs版的判环,bfs版的求最短路. 代码: #include<iostream> #include<ccty ...

随机推荐

  1. Eclipse在线安装STS插件

    转自:https://blog.csdn.net/weixin_41987553/article/details/81091280 spring Boot是由Pivotal团队提供的全新框架,其设计目 ...

  2. VBA 检查模块中是否有某个函数

    Function FindProcedures(ByRef wb As Workbook, ByVal Proc As String) As Boolean    On Error GoTo Exit ...

  3. AS3 注意点

    当主类new 一个主影片来放内容的时候.在gc此swf时,一定要检查此主影片是否存在,如 private function initStart() { //trace("RightMenu类 ...

  4. ios localization

    1. 在工程文件中选择支持的语言,“Localizations” 2. 添加资源文件 Localizable.strings, (app默认从该资源文件读取字符串) 3. 通过 NSLocalized ...

  5. python远程调试及celery调试

    部分来自 from: https://www.xncoding.com/2016/05/26/python/pycharm-remote.html 你是否经常要在Windows 7或MAC OS X上 ...

  6. mysql改数据库名称

    第一种方法: 1.创建需要改成新名的数据库.2.mysqldum 导出要改名的数据库3.删除原来的旧库(确定是否真的需要)当然这种方法虽然安全,但是如果数据量大,会比较耗时,哎,当时连这种方法都没有想 ...

  7. pycharm ideavimrc设置备忘

    文件存放位置 windows下 C:\Users\你的用户名\.ideavimrc 注:如果要映射pycharm 中的一些命令可以 在pycharm 中 edit->Macros->Sta ...

  8. Windows自带的端口转发工具netsh使用方法_DOS/BAT

    Windows自带的端口转发工具netsh使用方法_DOS/BAT   作者:用户 来源:互联网 时间:2017-02-22 17:24:30 netsh 端口转发 摘要: 下面的代码在windows ...

  9. 新手C#SQLServer在程序里实现语句的学习2018.08.12

    从C#中连接到SQL Server数据库,再通过C#编程实现SQL数据库的增删改查. ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤: 第一,使用SqlConnection对象连接数据 ...

  10. 重新认识trim,ltrim,rtrim,trailing和leading。

    trim经常用来去除一个字符串的空格,select trim(' dhajkjwa ') from dual; 在上面的语句中,trim的前面也可以加r或者l,表示去掉前面或者后面的空格,r和l代表左 ...