BZOJ 1123: [POI2008]BLO( tarjan )
2015-10-20 20:50
537 查看
tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下
-------------------------------------------------------------------------------
#include<cstdio>#include<cstring>#include<algorithm> using namespace std; typedef long long ll; const int maxn = 100009;const int maxm = 500009; struct edge { int to; edge* next;} E[maxm << 1], *pt = E, *head[maxn]; void add(int u, int v) { pt->to = v; pt->next = head[u]; head[u] = pt++;}void addedge(int u, int v) { add(u, v); add(v, u);} edge* Rev(edge* e) { return E + ((e - E) ^ 1);} int dfn[maxn], low[maxn], size[maxn], CK = 0, N;ll ans[maxn]; void tarjan(int x, edge* r) { dfn[x] = low[x] = ++CK; size[x] = 1; int cnt = 0; for(edge* e = head[x]; e; e = e->next) if(e != r) { if(!dfn[e->to]) { tarjan(e->to, Rev(e)); if(low[e->to] >= dfn[x]) ans[x] += cnt * size[e->to], cnt += size[e->to]; else low[x] = min(low[x], low[e->to]); size[x] += size[e->to]; } else low[x] = min(low[x], dfn[e->to]); } ans[x] += ll(cnt) * (N - cnt - 1);} void init() { int m; scanf("%d%d", &N, &m); while(m--) { int u, v; scanf("%d%d", &u, &v); addedge(--u, --v); }} void work() { memset(ans, 0, sizeof ans); memset(dfn, 0, sizeof dfn); memset(low, 0, sizeof low); for(int i = 0; i < N; i++) if(!dfn[i]) tarjan(i, NULL); for(int i = 0; i < N; i++) printf("%lld\n", 2LL * (ans[i] + N - 1));} int main() { init(); work(); return 0;}-------------------------------------------------------------------------------
1123: [POI2008]BLO
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 751 Solved: 309
[Submit][Status][Discuss]
Description
Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。Input
输入n<=100000 m<=500000及m条边Output
输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。Sample Input
5 51 2
2 3
1 3
3 4
4 5
Sample Output
88
16
14
8
HINT
Source
相关文章推荐
- 【MySQL】【leetcode】 Second Highest Salary解题报告
- tomcat部署好ok的工程访问显示404错误,跟没有部署一样的现象
- [iOS开发]UISplitViewController的使用
- 环形队列,用tag来标记队列的空(0)与满(1)
- 如何使用ICP算法
- 【简单并查集】Farm Irrigation
- c++笔记
- JS模块化历程
- vim 配置.vimrc文件
- HDU 1875 畅通工程再续(Prime,注意数据格式啊,老是在这方面出错)
- iOS项目中全局变量的定义与使用
- 美国国防部机密文件销毁算法
- 记录-C和指针第八章-数组
- api接口、RPC、WebService分别解决什么问题
- 一个简单地ViewPager自定义的轮播图
- 判断一个程序员水平高低的标准?
- LB Cluster 之三:持久连接及健康检测
- LSGO软件技术团队2015~2016学年第七周(1012~1018)总结
- iOS7编译错误:CGContextSaveGState...please set CG_CONTEXT_SHOW_BACKTRACE...
- git 在patch中的使用