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

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

P3469 [POI2008]BLO-Blockade

题目描述

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
#include
#include
#include
#define maxn 100010#ifdef WIN32#define PLL "%I64d"#else#define PLL "%lld"#endifusing namespace std;int n,m,cnt;int dfn[maxn],low[maxn],sz[maxn],head[maxn],num;long long ans[maxn];struct node{ int to,pre;}e[500010*2];void Insert(int from,int to){ e[++num].to=to; e[num].pre=head[from]; head[from]=num;}void Tarjan(int now){ int z=0;sz[now]=1; dfn[now]=low[now]=++cnt; for(int i=head[now];i;i=e[i].pre){ int to=e[i].to; if(!dfn[to]){ Tarjan(to); sz[now]+=sz[to]; low[now]=min(low[now],low[to]); if(dfn[now]<=low[to]){ ans[now]+=1LL*z*sz[to]; z+=sz[to]; } } else low[now]=min(low[now],dfn[to]); } ans[now]+=1LL*z*(n-z-1);}int main(){ scanf("%d%d",&n,&m); int x,y; for(int i=1;i<=m;i++){ scanf("%d%d",&x,&y); Insert(x,y);Insert(y,x); } for(int i=1;i<=n;i++) if(!dfn[i])Tarjan(i); for(int i=1;i<=n;i++) printf(PLL"\n",(ans[i]+n-1)<<1); return 0;}

 

转载于:https://www.cnblogs.com/thmyl/p/7742074.html

你可能感兴趣的文章
Devstack 安装OpenStack Pike版本(单机环境)
查看>>
Javascript 函数初探
查看>>
类的定义、声明使用
查看>>
转载,gini系数代码对应的公式
查看>>
编译安装mysql-5.6.40
查看>>
年终总结
查看>>
初创互联网公司技术架构变迁之路
查看>>
【BZOJ 3676】 3676: [Apio2014]回文串 (SAM+Manacher+倍增)
查看>>
【网络流24题】No. 13 星际转移问题 (网络判定 最大流)
查看>>
解析$.grep()源码及透过$.grep()看(两次取反)!!的作用
查看>>
[模板] 字符串hash
查看>>
SGU438_The Glorious Karlutka River =)
查看>>
Linux集群及LVS简介
查看>>
简单几何(直线与圆的交点) ZOJ Collision 3728
查看>>
Codeforces Round #327 (Div. 2)
查看>>
如何解决Provisional headers are shown问题(转)
查看>>
开发网站遇到的bug
查看>>
实现简单的接口自动化测试平台
查看>>
EXCEL工作表合并
查看>>
Prime Path
查看>>