[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. .
输入输出样例
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 ...
随机推荐
- 编译安装hadoop2.6.3
一.安装环境 1.1 JAVA 安装java1.7 下载jdk1.7: [root@node1~]# wget http://download.oracle.com/otn-pub/java/jd ...
- jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别
$().ready().$(handler).$(document).ready(handler)均不是原生JS中的,都是jQuery中封装的方法.这些事件在当页面的dom节点加载完毕后就执行,无需等 ...
- 第三课——MFC编程
一.MFC概述 1. MFC简述 MFC不仅仅是一套基础类库,更是一种编程方式. 2. MFC由来 1987年微软公司推出了第一代Windows产品,并为应用程序设计者提供了Win16(16位Wind ...
- 系统常量对话框QT实现
1.运行结果: 2.代码 main.cpp #include "constantdiag.h" #include <QtWidgets/QApplication> in ...
- C# Excel2007 导出生成 2003兼容格式
//导出2007格式 AppWb.Saved = true; //保存工作薄 AppExcel.ActiveWorkbook.SaveCopyAs(FilePath); //导出2003格式 AppW ...
- Apriori算法详解
一.Apriori 算法概述Apriori 算法是一种最有影响力的挖掘布尔关联规则的频繁项集的 算法,它是由Rakesh Agrawal 和RamakrishnanSkrikant 提出的.它使用一种 ...
- (转)linux IO 内核参数调优 之 参数调节和场景分析
1. pdflush刷新脏数据条件 (linux IO 内核参数调优 之 原理和参数介绍)上一章节讲述了IO内核调优介个重要参数参数. 总结可知cached中的脏数据满足如下几个条件中一个或者多个的时 ...
- Python对字符串进行MD5加密处理
import hashlibimport sysreload(sys)sys.setdefaultencoding('utf-8') m = hashlib.md5()m.update('123456 ...
- Delphi DBGridEH中,选中行、列、单元格
// 新增行后,默认首列 procedure TForm1.ADOQuery1AfterInsert(DataSet: TDataSet);begin with DBGridEh1 do begi ...
- 协程简介-异步IO
协程 1. 协程,又称微线程,纤程.协程是用户自己控制的,CPU根本不知道协程的存在,CPU只认识线程. 2. 线程切换的时候,会保存在CPU的寄存器里面. 协程切换的时候,却都是由用户自己的实现的. ...