BZOJ 1123: [POI2008]BLO tarjan求割点
来源:互联网 发布:我的世界端口查看器 编辑:程序博客网 时间:2024/04/29 17:57
时空隧道
仔细观察样例会发现其实(x,y)和(y,x)是不同的…
求割点…然后直接根据乘法原理计算答案就好了…
代码如下:
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>//by NeighThornusing namespace std;const int maxn=100000+5,maxm=500000+5;int n,m,hd[maxn],to[maxm*2],nxt[maxm*2],cnt,dfn[maxn],low[maxn*2],tim;long long ans[maxn];inline void add(int x,int y){ to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++;}inline long long tarjan(int root,int f){ dfn[root]=low[root]=++tim;long long tmp=0,sum=0;ans[root]=(n-1)<<1;int cnt=0,siz; for(int i=hd[root];i!=-1;i=nxt[i]) if(to[i]!=f){ if(!dfn[to[i]]){ siz=tarjan(to[i],root);low[root]=min(low[root],low[to[i]]); if(low[to[i]]>=dfn[root]) ans[root]+=2LL*siz*sum,sum+=siz; else tmp+=siz; } else low[root]=min(low[root],dfn[to[i]]); } ans[root]+=2LL*(n-(sum+1))*sum; return sum+tmp+1;}signed main(void){ tim=cnt=0; scanf("%d%d",&n,&m); memset(hd,-1,sizeof(hd)); memset(dfn,0,sizeof(dfn)); for(int i=1,x,y;i<=m;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x); tarjan(1,-1); for(int i=1;i<=n;i++) printf("%lld\n",ans[i]); return 0; }
by >_< NeighThorn
0 0
- BZOJ 1123: [POI2008]BLO tarjan求割点
- 【tarjan】【bzoj 1123】: [POI2008]BLO
- 1123: [POI2008]BLO tarjan求割点
- BZOJ 1123: [POI2008]BLO 点双联通,Tarjan求割点
- BZOJ 1123 POI2008 BLO Tarjan+树形DP
- BOZJ 1123: [POI2008]BLO tarjan求割点
- BZOJ 1123: [POI2008]BLO
- bzoj 1123 [POI2008]BLO
- bzoj 1123: [POI2008]BLO
- bzoj 1123: [POI2008]BLO (tarjan求点双+树形DP)
- bzoj1123 [POI2008]BLO(tarjan求割点)
- [BZOJ]1123 [POI2008]BLO 割点
- BZOJ 1123: [POI2008]BLO 图的连通性
- 【bzoj1123】【[POI2008]BLO】tarjan判割点
- BZOJ 1123 POI 2008 BLO题解 Tarjan求割点+乘法原理
- BZOJ 1123 [POI2008]BLO 点双连通分量
- BZOJ 1123: [POI2008]BLO [割点][乘法原理]
- 【BZOJ】【P1123】【POI2008】【BLO】【题解】【割点】
- 为什么自定义ViewGroup ondraw方法不会被调用
- 周六计划
- Hadoop 面试思考
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- 票据业务解析
- BZOJ 1123: [POI2008]BLO tarjan求割点
- 第十一周—查找闰年
- 403. Frog Jump
- ios 图片处理( 1.按比例缩放 2.指定宽度按比例缩放)
- Spring AOP中JdkDynamicAopProxy源码介绍
- 当Swiper轮播图效果遇上angular.js的ng-repeat
- struts的ActionContext详解
- 项目部署到IIS,并实现可调试
- 69道Spring面试题和答案