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个点不连通,点对是 ...
随机推荐
- python 多线程笔记(3)-- 线程的私有命名空间
线程的私有命名空间实现: threading_namespace = threading.local() import threading import time import random thre ...
- 【BZOJ1951】[SDOI2010]古代猪文
[BZOJ1951][SDOI2010]古代猪文 题面 bzoj 洛谷 题解 题目实际上是要求 $ G^{\sum d|n\;C_n^d}\;mod \; 999911659 $ 而这个奇怪的模数实际 ...
- [SDOI2011]染色 树链剖分
LG传送门 我写这道题的题解主要是因为洛谷上的题解要么讲的不清要么代码丑滑稽,导致初学时的我调了很久,所以想发个题解方便后来人. 由于要维护的信息还是具有区间可加性,只需要记录一下每个区间的左右端点颜 ...
- jquery.validate使用 - 4
自定义错误消息的显示方式 默认情况下,验证提示信息用label元素来显示, 并且会添加css class, 通过css可以很方便设置出错控件以及错误信息的显示方式. /* 输入控件验证出错*/form ...
- LUA中点号和冒号的区别
Student = {}; Student.__index = Student; function Student:new(name, age) local temp = {}; setmetatab ...
- mono for andorid第一个小应用
先上图 这个小应用根据两人的姓名算出两人的关系,当然仅仅娱乐. 本来想多写写,但是实在觉得没什么可写的,而且本人正处于感冒状态,脑袋不怎么灵光,所以就不写那么多废话了. 安装mono的话,就上吾乐吧软 ...
- Node2vec 代码分析
Node2vec 代码从Github上clone到本地,主要是main.py和node2vec.py两个文件. 下面把我的读代码注释放到上面来, import numpy as np import n ...
- Linux虚拟机centos系统安装
linux 其他知识目录 安装完后如果虚拟机网络不通请参考:虚拟机网络不通故障解决 1.centos6.9安装 后面安装出了点问题,ip没有并且eth0网卡找不到,不过重新配置ifcfg-eth0后重 ...
- Kickstart 安装centos7
以前是怎么安装系统的 光盘(ISO文件,光盘的镜像文件)===>每一台物理机都得给一个光驱,如果用外置光驱的话,是不是每台机器都需要插一下 U盘:ISO镜像刻录到U盘==>需要每台机器都需 ...
- gulp配置文件(gulpfile.js)
需要安装的插件 "gulp": "^3.9.1","gulp-clean": "^0.3.2","gulp-c ...