P3469 [POI2008]BLO-Blockade

题意翻译

在Byteotia有n个城镇。 一些城镇之间由无向边连接。 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些)。每两个城镇之间至多只有一条直接连接的道路。人们可以从任意一个城镇直接或间接到达另一个城镇。 每个城镇都有一个公民,他们被孤独所困扰。事实证明,每个公民都想拜访其他所有公民一次(在主人所在的城镇)。所以,一共会有n*(n-1)次拜访。

不幸的是,一个程序员总罢工正在进行中,那些程序员迫切要求购买某个软件。

作为抗议行动,程序员们计划封锁一些城镇,阻止人们进入,离开或者路过那里。

正如我们所说,他们正在讨论选择哪些城镇会导致最严重的后果。

编写一个程序:

读入Byteotia的道路系统,对于每个被决定的城镇,如果它被封锁,有多少访问不会发生,输出结果。

输入输出格式

第一行读入n,m,分别是城镇数目和道路数目

城镇编号1~n

接下来m行每行两个数字a,b,表示a和b之间有有一条无向边

输出n行,每行一个数字,为第i个城镇被锁时不能发生的访问的数量。



@[chen_zhe](/space/show?uid=8457)

翻译提供者:Park

题目描述

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: nn and mm (1\le n\le 100\ 0001≤n≤100 000, 1\le m\le 500\ 0001≤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 aa and bb (1\le a<b\le n1≤a<b≤n) and denotes a direct road between towns numbered aaand bb.

输出格式:

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

输入输出样例

输入样例#1: 复制

5 5
1 2
2 3
1 3
3 4
4 5
输出样例#1: 复制

8
8
16
14
8
/*
显然割点比较特殊。其余点对答案贡献为(n-1)*2
删掉割点后会形成很多联通块,需要用Tarjan求出每个联通快的点数
答案就是乘一乘加一加。
注意Tarjan是按dfs序遍历的。假设把原图“缩点”形成一棵树
那么Tarjan统计的联通块点数一定是他的子树。对于它的祖先点数,用总数减一减就好。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define ll long long
#define N 1000007
#define M 1000007 using namespace std;
int n,m,cnt,top;
int head[N],dfn[N],low[N],size[N];
ll ans[N];
bool cut[N];
struct edge{
int u,v,net;
}e[N]; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} inline void add(int u,int v)
{
e[++cnt].v=v;e[cnt].net=head[u];head[u]=cnt;
} void Tarjan(int u)
{
dfn[u]=low[u]=++cnt;
int sum=,flag=;size[u]=;
for(int i=head[u];i;i=e[i].net)
{
int v=e[i].v;
if(!dfn[v])
{
Tarjan(v);size[u]+=size[v];
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
ans[u]+=(ll)size[v]*(n-size[v]);
sum+=size[v]; flag++;
if(u!= || flag>) cut[u]=;
}
}
else low[u]=min(low[u],dfn[v]);
}
if(!cut[u]) ans[u]=*(n-);
else ans[u]+=(ll)(n-sum-)*(sum+)+(n-);
} int main()
{
int x,y;
n=read();m=read();
for(int i=;i<=m;i++)
{
x=read();y=read();
add(x,y);add(y,x);
}cnt=;
Tarjan();
for(int i=;i<=n;i++) printf("%lld\n",ans[i]);
return ;
}

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

  1. 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)

    P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...

  2. [POI2008]BLO(Tarjan)

    [POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...

  3. 【bzoj1123】【[POI2008]BLO】tarjan判割点

    (上不了p站我要死了,侵权度娘背锅) Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有t ...

  4. BZOJ 1123 [POI2008]BLO(Tarjan算法)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1123 [题目大意] Byteotia城市有n个towns,m条双向roads. 每条r ...

  5. 【BZOJ1123】 [POI2008]BLO (tarjan)

    tarjan判断割点...拿掉一个点之后,会被分成若干个联通块,用节点个数和统计一下他们相互不能到达的个数就好. ; maxm=; type edgetype=record toward,next:l ...

  6. bzoj 1123 [POI2008]BLO Tarjan求割点

    [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1540  Solved: 711[Submit][Status][Discu ...

  7. BZOJ 1123: [POI2008]BLO( tarjan )

    tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...

  8. [Luogu P3469] [POI2008]BLO-Blockade (割点)

    题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...

  9. BZOJ 1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1030  Solved: 440[Submit][Status] ...

随机推荐

  1. unity 菜单栏添加新菜单

    using UnityEngine; using System.Collections; using UnityEditor; public class jqmTools : CreateSphere ...

  2. 【04】AJAX接收服务器返回的数据

    AJAX接收服务器返回的数据 readyState 和 status 属性 readyState 属性保存有 XMLHttpRequest 对象的交互状态,从 0 到 4 变化: 0 :未初始化(还没 ...

  3. JS数组添加元素的三种方式

    1.push() 结尾添加 数组.push(元素) 参数 描述 newelement1 必需.要添加到数组的第一个元素. newelement2 可选.要添加到数组的第二个元素. newelement ...

  4. TKmybatis的框架介绍和原理分析及Mybatis新特性

    tkmybatis是在mybatis框架的基础上提供了很多工具,让开发更加高效,下面来看看这个框架的基本使用,后面会对相关源码进行分析,感兴趣的同学可以看一下,挺不错的一个工具 实现对员工表的增删改查 ...

  5. Linux下汇编语言学习笔记47 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  6. sql将日期按照年月分组并统计数量

    SELECT DATE_FORMAT(releaseDate,"%Y年%m月") AS dates,COUNT(*) FROM t_diary GROUP BY DATE_FORM ...

  7. poj——1470 Closest Common Ancestors

    Closest Common Ancestors Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 20804   Accept ...

  8. Nginx与HAProxy的区别

    对于做软负载,我们都知道主流的方案有LVS.Haproxy.Nginx!那么对于Haproxy和Nginx,我们如何选择呢?回答这个问题之前,我根据个人使用经验来讲下它们的特点! Haproxy特点 ...

  9. JDBC的存储过程

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/stored-procedure.html: 正如一个Connection对象创建了Statement和 ...

  10. Servlet的文件上传

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/file-uploading.html: Servlet可以与HTML form标签一起使用允许用 ...