P3469 [POI2008]BLO-Blockade(Tarjan 割点)
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.
输入输出样例
5 5
1 2
2 3
1 3
3 4
4 5
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 割点)的更多相关文章
- 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)
P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...
- [POI2008]BLO(Tarjan)
[POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...
- 【bzoj1123】【[POI2008]BLO】tarjan判割点
(上不了p站我要死了,侵权度娘背锅) Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有t ...
- BZOJ 1123 [POI2008]BLO(Tarjan算法)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1123 [题目大意] Byteotia城市有n个towns,m条双向roads. 每条r ...
- 【BZOJ1123】 [POI2008]BLO (tarjan)
tarjan判断割点...拿掉一个点之后,会被分成若干个联通块,用节点个数和统计一下他们相互不能到达的个数就好. ; maxm=; type edgetype=record toward,next:l ...
- bzoj 1123 [POI2008]BLO Tarjan求割点
[POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1540 Solved: 711[Submit][Status][Discu ...
- BZOJ 1123: [POI2008]BLO( tarjan )
tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...
- [Luogu P3469] [POI2008]BLO-Blockade (割点)
题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...
- BZOJ 1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1030 Solved: 440[Submit][Status] ...
随机推荐
- 洛谷 P2285 BZOJ 1207 [HNOI2004]打鼹鼠
题目描述 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的.根据这个特点阿牛编写了一个打鼹鼠的游戏:在一个n*n的网格中,在某些时刻鼹鼠会在某一个网格探出头来透透气. ...
- P1072 Hankson的趣味题
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- js数组转换成json串 (JSON.stringify)
例如: var giftlist[1490011777] = []; giftlist[1490011777]['id'] = 1490011777; giftlist[1490011777]['na ...
- HDU1166 线段树裸题 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...
- 系统无法安装 OfficeControl.ocx 控件如何解决
在OA上要直接查看word等公告文件,就必须安装office控件.要安装office控件,需要在IE浏览器中做相应的设置.如何设置呢,下面由小编具体介绍下. 工具/原料 OA IE浏览器 方法 ...
- ETL增量单表同步简述_根据timestamp增量
ETL增量单表同步简述 1. 实现需求 当原数据库的表有新增.更新.删除操作时,将改动数据同步到目标库对应的数据表. 2. 设计思路 设计总体流程图如下: 步骤简单说明: 1.设置job的执行属性,如 ...
- how to read openstack code : paste deploy
本篇分为以下几个部分 paste 是什么 怎样使用paste paste of neutron paste 是什么 WSGI 是python 中application 和 web server互通的标 ...
- go-import下划线的作用
原文:http://studygolang.com/articles/4356 ------------------------------------------------------------ ...
- C# .NET 如何批量增加或取消注释
选中一批文本之后 批量增加注释:Ctrl+K Ctrl+C 批量取消注释:Ctrl+K Ctrl+U