BZOJ1123 BLO [Tarjan][点双连通分量]
来源:互联网 发布:软件系统可靠性设计 编辑:程序博客网 时间:2024/05/16 14:05
就是点双连通分量的裸题,我们记录一个siz,如果某个点可以搜到low比它的deep值大的点的话,显然是产生了一个分割后的连通块。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>#include<map>#include<set>#include<vector>#include<queue>#define pa pair<int,int>#define inf 1000000000#define ll long long using namespace std;inline void read(int &res){ int flag=1;static char ch; while((ch=getchar())<'0'||ch>'9')if(ch=='-')flag=-1;res=ch-48; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;res*=flag;}int n,m,cnt,tot;int head[100005],size[100005],dfn[100005],low[100005];ll ans[100005];struct data{int to,next;}E[1000005];void addedge(int u,int v){ E[++tot].to=v;E[tot].next=head[u];head[u]=tot; E[++tot].to=u;E[tot].next=head[v];head[v]=tot;}void tarjan(int x){ int t=0; size[x]=1; dfn[x]=low[x]=++cnt; for(int i=head[x];i;i=E[i].next) if(dfn[E[i].to])low[x]=min(low[x],dfn[E[i].to]); else{ tarjan(E[i].to); size[x]+=size[E[i].to]; low[x]=min(low[x],low[E[i].to]); if(dfn[x]<=low[E[i].to]){ ans[x]+=(ll)t*size[E[i].to]; t+=size[E[i].to]; } } ans[x]+=(ll)t*(n-t-1);}int main(){ read(n),read(m); for(int u,v,i=1;i<=m;i++) read(u),read(v),addedge(u,v); tarjan(1); for(int i=1;i<=n;i++) printf("%lld\n",(ans[i]+n-1)*2); return 0;}
阅读全文
0 0
- BZOJ1123 BLO [Tarjan][点双连通分量]
- BZOJ 1123 [POI2008]BLO 点双连通分量
- 点/边 双连通分量---Tarjan算法
- POJ1523 SPF【点双连通分量】【Tarjan】
- tarjan求点的双连通分量
- BZOJ1123 BLO(tarjan割点)
- 双连通分量-tarjan
- 双连通分量-tarjan
- 点双连通分量
- 点双连通分量
- 点双连通分量
- 点双连通分量
- 【tarjan求解双连通分量】
- [双连通分量] tarjan算法
- tarjan算法-双连通分量
- 关于Tarjan算法求点双连通分量
- 点双连通分量的求解 Tarjan算法的拓展
- tarjan算法应用 割点 桥 双连通分量
- GreenDao清空数据库的方法
- 约数的个数
- Django入门-6:视图(URLconf使用)
- 分布式系统设计之基础设施(二)
- Java设计模式-策略模式
- BZOJ1123 BLO [Tarjan][点双连通分量]
- 标准盒子模型和IE盒子模型
- SQL一般面试题
- centos7更新系统内核及软件
- Leetcode : Edit Distance
- Realm For Android详细教程
- CentOS命令
- 现阶段学习计划
- python:pandas(5),层次化索引