题意翻译

在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 .

输入输出样例

输入样例#1:

5 5
1 2
2 3
1 3
3 4
4 5
输出样例#1:

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的更多相关文章

  1. BZOJ 1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1030  Solved: 440[Submit][Status] ...

  2. BZOJ1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 614  Solved: 235[Submit][Status] ...

  3. BZOJ 1123: [POI2008]BLO( tarjan )

    tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...

  4. bzoj 1123 [POI2008]BLO Tarjan求割点

    [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1540  Solved: 711[Submit][Status][Discu ...

  5. P3469 [POI2008]BLO-Blockade(Tarjan 割点)

    P3469 [POI2008]BLO-Blockade 题意翻译 在Byteotia有n个城镇. 一些城镇之间由无向边连接. 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些).每 ...

  6. 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)

    P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...

  7. [POI2008]BLO(Tarjan)

    [POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...

  8. [Luogu P3469] [POI2008]BLO-Blockade (割点)

    题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...

  9. 【luogu P3469 [POI2008]BLO-Blockade】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3469 #include <cstdio> #include <cstring> #i ...

  10. [LUOGU] P3469 [POI2008]BLO-Blockade

    https://www.luogu.org/problemnew/show/P3469 求无向图分别删去每个点后不连通的点对数. 首先,对于任何一个点,它本身删了,就会和剩下的n-1个点不连通,点对是 ...

随机推荐

  1. python 多线程笔记(3)-- 线程的私有命名空间

    线程的私有命名空间实现: threading_namespace = threading.local() import threading import time import random thre ...

  2. MySQL入门篇(四)之MySQL主从复制

    一.MySQL主从复制原理 随机站点访问量的鞥集啊,单台的MySQL服务器压力也不断地增加,此时需要对MySQL进行优化,如果在MySQL优化无明显改善时期,可以使用高可用.主从复制.读写分离.分库分 ...

  3. 数据库路由中间件MyCat - 源代码篇(15)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. public static void handle(String stmt, ServerConnectio ...

  4. 学习HTML 第四节.插入图像

    学习HTML 第四节.插入图像 全是文字的网页太枯燥了吧,我们来搞个图片上去! <!DOCTYPE html><html><head><meta charse ...

  5. 180729-Quick-Task 动态脚本支持框架之任务动态加载

    Quick-Task 动态脚本支持框架之任务动态加载 前面几篇博文分别介绍了整个项目的基本架构,使用说明,以及整体框架的设计与实现初稿,接下来则进入更细节的实现篇,将整个工程中核心实现捞出来,从为什么 ...

  6. Python接口测试实战3(下)- unittest测试框架

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  7. Unity3D之AR开发(二)

    上一篇给大家介绍了高通AR的使用,接下来给大家分享一下EasyAR EasyAR引擎简介 EasyAR是做好用的且免费的增强现实(Augmented Reality)引擎,EasyAR为Unity开发 ...

  8. 【转】AOE机制的DSL及其实际运用

    AOE这个词的意思,我相信玩过WOW的人都不陌生,包括玩过LoL的也不会陌生,说穿了就是一个区域内发生效果(Area of effect).这里我们要讨论的就是关于一个适合于几乎所有游戏的AOE机制, ...

  9. JavaScript学习笔记(四)——DOM

    第五章 网页交互——文本对象模型[Document object model] 1 简单介绍DOM,dom是将html与javascript进行交互的工具. [使用innerHTML时注意:html中 ...

  10. C语言—栈

    栈的操作:进栈和出栈 #include "stdafx.h" #include "stack.h" #define maxsize 20 typedef int ...