P3469 [POI2008]BLO-Blockade
题意翻译
在Byteotia有n个城镇。 一些城镇之间由无向边连接。 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些)。每两个城镇之间至多只有一条直接连接的道路。人们可以从任意一个城镇直接或间接到达另一个城镇。 每个城镇都有一个公民,他们被孤独所困扰。事实证明,每个公民都想拜访其他所有公民一次(在主人所在的城镇)。所以,一共会有n*(n-1)次拜访。
不幸的是,一个程序员总罢工正在进行中,那些程序员迫切要求购买某个软件。
作为抗议行动,程序员们计划封锁一些城镇,阻止人们进入,离开或者路过那里。
正如我们所说,他们正在讨论选择哪些城镇会导致最严重的后果。
编写一个程序:
读入Byteotia的道路系统,对于每个被决定的城镇,如果它被封锁,有多少访问不会发生,输出结果。
输入输出格式
第一行读入n,m,分别是城镇数目和道路数目
城镇编号1~n
接下来m行每行两个数字a,b,表示a和b之间有有一条无向边
输出n行,每行一个数字,为第i个城镇被锁时不能发生的访问的数量。
题目描述
There are exactly nnn 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⋅(n−1)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: nnn and mmm ( 1≤n≤100 0001\le n\le 100\ 0001≤n≤100 000 , 1≤m≤500 0001\le m\le 500\ 0001≤m≤500 000 ) denoting the number of towns and roads, respectively.
The towns are numbered from 1 to nnn .
The following mmm lines contain descriptions of the roads.
Each line contains two integers aaa and bbb ( 1≤a<b≤n1\le a<b\le n1≤a<b≤n ) and denotes a direct road between towns numbered aaa and bbb .
输出格式:
Your programme should write out exactly nnn integers to the standard output, one number per line. The ithi^{th}ith line should contain the number of visits that could not take place if the programmers blocked the town no. iii .
输入输出样例
5 5
1 2
2 3
1 3
3 4
4 5
8
8
16
14
8
Solution:
Tarjan+简单数学。
对于一个点,分两种情况判断:
1、非割点,那么割掉改点会使得剩下的$n-1$个点与该点不联通,答案就是$2\times (n-1)$。
2、割点,与其相连的割点对答案的贡献为$siz[v]\times (n-siz[v])$,非割点答案贡献为$(n-1-\sum{siz[v]})\times (1+\sum{siz[v]})$,最后还得算上该点减少的组合$n-1$。
实现过程直接在tarjan求割点的同时,统计下子树大小,计算答案就好了。
代码:
/*Code by 520 -- 8.22*/
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define RE register
#define For(i,a,b) for(RE int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(RE int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=;
int n,m,low[N],dfn[N],siz[N],tot;
int to[N],net[N],h[N],cnt;
int scc,bl[N],stk[N],top;
ll ans[N];
bool cut[N]; int gi(){
int a=;char x=getchar();
while(x<''||x>'')x=getchar();
while(x>=''&&x<='')a=(a<<)+(a<<)+(x^),x=getchar();
return a;
} il void add(int u,int v){to[++cnt]=v,net[cnt]=h[u],h[u]=cnt;} void tarjan(int u){
dfn[u]=low[u]=++tot,siz[u]=;
int ppx=,sum=;
for(RE int i=h[u];i;i=net[i])
if(!dfn[to[i]]){
tarjan(to[i]),
siz[u]+=siz[to[i]],
low[u]=min(low[u],low[to[i]]);
if(low[to[i]]>=dfn[u]){
ppx++;
ans[u]+=1ll*siz[to[i]]*(n-siz[to[i]]);
sum+=siz[to[i]];
if(u!=||ppx>) cut[u]=;
}
}
else low[u]=min(low[u],dfn[to[i]]);
if(cut[u]) ans[u]+=1ll*(n-sum-)*(sum+)+(n-);
else ans[u]=n-<<;
} il void init(){
n=gi(),m=gi();
int u,v;
For(i,,m) {
u=gi(),v=gi();
if(u!=v) add(u,v),add(v,u);
}
tarjan();
For(i,,n) printf("%lld\n",ans[i]);
} int main(){
init();
return ;
}
P3469 [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 ...
- P3469 [POI2008]BLO-Blockade(Tarjan 割点)
P3469 [POI2008]BLO-Blockade 题意翻译 在Byteotia有n个城镇. 一些城镇之间由无向边连接. 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些).每 ...
- 洛谷 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. 所 ...
- [Luogu P3469] [POI2008]BLO-Blockade (割点)
题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...
- 【luogu P3469 [POI2008]BLO-Blockade】 题解
题目链接:https://www.luogu.org/problemnew/show/P3469 #include <cstdio> #include <cstring> #i ...
- [LUOGU] P3469 [POI2008]BLO-Blockade
https://www.luogu.org/problemnew/show/P3469 求无向图分别删去每个点后不连通的点对数. 首先,对于任何一个点,它本身删了,就会和剩下的n-1个点不连通,点对是 ...
随机推荐
- C#特性的简单介绍
特性应该我们大多接触过,比喻经常使用的[Obsolete],[Serializable]等下面我就主要介绍一个特性的一些用法 摘自MSDN定义:用以将元数据或声明信息与代码(程序集.类型.方法.属性等 ...
- Qt 利用XML文档,写一个程序集合 三
接上一篇https://www.cnblogs.com/DreamDog/p/9214052.html 滚动区域实现, 滚动区域可以三成分层 第一层,显示内容 中间层,滚动层 第三层,爸爸层 把我们要 ...
- Jenkins配置 管理
Jenkins配置 你可能已经看了前面几次练习了,其中我们不得不在Jenkins配置选项.下表列出了Jenkins 的各种配置选项. 因此,可以通过点击左侧菜单侧的 “Manage Jenkins”选 ...
- 【bzm-Random CSV Data Set Config】 -jmeter - 文件中随机取参的方法,(插件自带)
文件中随机取参数的方法 Random CSV Data Set Config
- 微信小程序转换为百度小程序
据粗略预估,微信小程序和百度小程序,有至少90%以上的相似代码,而且api的参数和返回的数据都是一致的,有一些不一致的将做如下介绍:.wxml文件,改成后辍名.swan.wxss文件,改成后辍名为.c ...
- winform圆角窗体实现
winform圆角窗体实现 1.窗体的FormBorderStyle设置成None,不要控制边框 2.TransparencyKey和BackColor颜色设置成相同的,这样,窗体就透明了 3.以此为 ...
- [笔记] FreeBSD使用小技巧
非交互式添加用户 sed直接修改文件 sed -i '' 's/a/b/' file sed添加一行 sed '1a\ newline' file sed '1s/.*/&\'$'\nnewl ...
- 《数据结构与算法JavaScript描述》中的一处错误
最近在看<数据结构与算法JavaScript描述>这本书,看到选择排序这部分时,发现一个比较大的错误. 原书的选择排序算法是这样的: function selectionSort() { ...
- USACO 3.3.1 Riding the Fences 骑马修栅栏(欧拉回路)
Description 农民John每年有很多栅栏要修理.他总是骑着马穿过每一个栅栏并修复它破损的地方. John是一个与其他农民一样懒的人.他讨厌骑马,因此从来不两次经过一个一个栅栏.你必须编一个程 ...
- 冲刺ing-2
第二次Scrum冲刺 队员完成的任务 队员 完成任务 吴伟华 分配任务 蔺皓雯 编写博客,查阅资料 蔡晨旸 查阅资料 曾茜 暂无 鲁婧楠 暂无 杨池宇 暂无 成员遇到的问题 队员 问题 吴伟华 暂无 ...