[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  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.
.
输入输出样例
5 5
1 2
2 3
1 3
3 4
4 5
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*],nxt[M*],tot=;
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=; 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-);
}
int main()
{
scanf("%d%d",&n,&m);
int u,v;
while(m--)
{
scanf("%d%d",&u,&v);
add(u,v);
}
tot=;
tarjan();
for(int i=;i<=n;i++) printf("%lld\n",ans[i]+n-<<);
}
[POI2008]BLO-Blockade的更多相关文章
- BZOJ 1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1030 Solved: 440[Submit][Status] ...
- BZOJ1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 614 Solved: 235[Submit][Status] ...
- BZOJ 1123: [POI2008]BLO( tarjan )
tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...
- bzoj 1123 [POI2008]BLO Tarjan求割点
[POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1540 Solved: 711[Submit][Status][Discu ...
- [POI2008]BLO(Tarjan)
[POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...
- 【dfs+连通分量】Bzoj1123 POI2008 BLO
Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...
- 割点判断+luogu 3469 POI2008 BLO
1.根节点,有2棵及以上子树 2.非根节点,有子节点dfn[u]<=low[v] #include <bits/stdc++.h> #define N 1000050 using n ...
- [POI2008] BLO
link 试题分析 分两种情况考虑. 当此点不是割点是,答案是$2\times (n-1)$. 当是割点时,我们发现这个点把树分成了若干个联通块,只要两两相乘即可. #include<iostr ...
- BZOJ 1123 [POI2008]BLO(Tarjan算法)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1123 [题目大意] Byteotia城市有n个towns,m条双向roads. 每条r ...
- BZOJ1123:[POI2008]BLO(双连通分量)
Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...
随机推荐
- 卸载CDH5.7
CDH5.7卸载1.记录用户数据目录2.关闭所有服务2.1在CM中,选择某个集群,然后停止集群.2.2逐个关闭CDH中的服务3.删除parcels4.删除集群5.卸载Cloudera manager ...
- PHP中通过preg_match_all函数获取页面信息并过滤变更为数组存储模式
// 1. 初始化 $ch = curl_init(); // 2. 设置选项 curl_setopt($ch, CURLOPT_URL, "http://test.com/index.js ...
- NFS服务搭建使用
需求:由于线上业务有一些数据存在了Redis数据库和mysql数据库中了,导致了数据较大迁移起来比较麻烦,所以准备搭建NFS来做WEB的共享磁盘,存储这些数据. 服务端搭建: 查看本机关于nfs的包 ...
- Thunder团队第五周 - Scrum会议2
Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...
- Pipeline组Alpha版本发布说明
Pipeline组Alpha版本发布说明 项目名称 Pipeline 项目版本 Alpha版本 负责人 北京航空航天大学计算机学院 ILoveSE 联系方式 http://www.cnblogs.co ...
- (一)Model的产生及处理
MVC的概念其实最早可以追溯到很久很久以前,并不是WEB开发过程中所首创, 但是,MVC也适合WEB上的开发,并真正的在WEB开发领域广泛应用.MVC的第一个字母M是Model,承载着View层和Co ...
- mysql入门 — (2)
创建表 CREATE TABLE 表名称 [IF NOT EXISTS]( 字段名1 列类型[属性] [索引] 字段名2 列类型[属性] [索引] ... 字段名n 列类型[属性] [索引] )[表类 ...
- MFC修改视图CView的背景颜色
(1) 在CYournameView(就是你的视图类,以下以CDrawLineView为例)添加了一个背景颜色变量 COLORREF m_bgcolor; (2)修改这个函数: BOOL CDrawL ...
- HDU 2115 I Love This Game
http://acm.hdu.edu.cn/showproblem.php?pid=2115 Problem Description Do you like playing basketball ? ...
- 让你的SilverLight程序部署在任意服务器上
是的,即使是免费的只支持HTML的空间,同样可以部署SilverLight应用.众所周知,SilverLight的部署问题其实就是.xap文件名是否能被服务器支持的问题.解决的方法无非就是添加MIME ...