博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Tarjan][割点] 洛谷 P3469 BLO-Blockade
阅读量:4576 次
发布时间:2019-06-08

本文共 3762 字,大约阅读时间需要 12 分钟。

题意翻译

在Byteotia有n个城镇。 一些城镇之间由无向边连接。 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些)。每两个城镇之间至多只有一条直接连接的道路。人们可以从任意一个城镇直接或间接到达另一个城镇。 每个城镇都有一个公民,他们被孤独所困扰。事实证明,每个公民都想拜访其他所有公民一次(在主人所在的城镇)。所以,一共会有n*(n-1)次拜访。

不幸的是,一个程序员总罢工正在进行中,那些程序员迫切要求购买某个软件。

作为抗议行动,程序员们计划封锁一些城镇,阻止人们进入,离开或者路过那里。

正如我们所说,他们正在讨论选择哪些城镇会导致最严重的后果。

编写一个程序:

读入Byteotia的道路系统,对于每个被决定的城镇,如果它被封锁,有多少访问不会发生,输出结果。

输入输出格式

第一行读入n,m,分别是城镇数目和道路数目

城镇编号1~n

接下来m行每行两个数字a,b,表示a和b之间有有一条无向边

输出n行,每行一个数字,为第i个城镇被锁时不能发生的访问的数量。

@[chen_zhe](/space/show?uid=8457)翻译提供者:Park

题目描述

There are exactly nn 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\cdot (n-1)n(n1) 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: nn and mm (1\le n\le 100\ 0001n100 000, 1\le m\le 500\ 0001m500 000) denoting the number of towns and roads, respectively.

The towns are numbered from 1 to nn.

The following mm lines contain descriptions of the roads.

Each line contains two integers aa and bb (1\le a<b\le n1a<bn) and denotes a direct road between towns numbered aa and bb.

 

输出格式:

 

Your programme should write out exactly nn integers to the standard output, one number per line. The i^{th}ith line should contain the number of visits that could not take place if the programmers blocked the town no. ii.

 

输入输出样例

输入样例#1:
5 51 22 31 33 44 5
输出样例#1:
8816148

 

 

题解

  • 我们对于一个点出去他所到达的和能到达它的之外,剩下的就是他相连的联通块之间的相连的了

  • 在tarjan里面,我们处理出这个点所能到达且是他的子树的的联通块的大小

  • 这样他的父亲树的大小就为总点数减去这个点减去他的子树的大小,即n-1-size[i]

  • 这样我们又能得知他们之间不能相连的点数就是他的父亲节点内的个数*子树节点内的个数

  • 这样我们求出了从该点外不能互相到达的对数,再加上它能到达的点的对数就是了

  • 不过这里我们处理出来的是单向到达,乘二就完事了

代码

1 #include 
2 #include
3 #include
4 #define N 100010 5 #define ll long long 6 using namespace std; 7 int n,m,cnt,dfn[N],low[N],size[N],head[N]; 8 ll ans[N]; 9 struct edge { int from,to;}e[1000005];10 void insert(int x,int y)11 {12 e[++cnt].to=y,e[cnt].from=head[x],head[x]=cnt;13 e[++cnt].to=x,e[cnt].from=head[y],head[y]=cnt;14 }15 void tarjan(int x)16 {17 dfn[x]=low[x]=++dfn[0],size[x]=1;18 int r=0;19 for (int i=head[x];i;i=e[i].from)20 if (!dfn[e[i].to])21 {22 tarjan(e[i].to),size[x]+=size[e[i].to],low[x]=min(low[x],low[e[i].to]);23 if (dfn[x]<=low[e[i].to]) ans[x]+=(ll)r*size[e[i].to],r+=size[e[i].to];24 }25 else low[x]=min(low[x],dfn[e[i].to]);26 ans[x]+=(ll)r*(n-r-1);27 }28 int main()29 {30 scanf("%d%d",&n,&m);31 for (int i=1,a,b;i<=m;i++) scanf("%d%d",&a,&b),insert(a,b);32 tarjan(1); 33 for (int i=1;i<=n;i++) printf("%lld\n",(ans[i]+n-1)*2);34 }

 

转载于:https://www.cnblogs.com/Comfortable/p/10331935.html

你可能感兴趣的文章
js URL中文传参乱码
查看>>
Leetcode 367. Valid Perfect Square
查看>>
UVALive 3635 Pie(二分法)
查看>>
win系统查看自己电脑IP
查看>>
Backup&recovery备份和还原 mysql
查看>>
一道面试题及扩展
查看>>
Unity 3D 我来了
查看>>
setup elk with docker-compose
查看>>
C++ GUI Qt4学习笔记03
查看>>
Java基础回顾 —反射机制
查看>>
c# 前台js 调用后台代码
查看>>
2017-02-20 可编辑div中如何在光标位置添加内容
查看>>
$.ajax()方法详解
查看>>
jquery操作select(增加,删除,清空)
查看>>
Sublimetext3安装Emmet插件步骤
查看>>
MySQL配置参数
查看>>
全面理解Java内存模型
查看>>
存储过程
查看>>
生成器
查看>>
将一个数的每一位都取出来的方法!
查看>>