【模板】强连通分量
来源:互联网 发布:matlab怎么调用caffe 编辑:程序博客网 时间:2024/06/05 02:43
#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<iostream>#include<string>#include<cstdlib>#include<stack>using namespace std;stack <int> q;int hed[1000005],nex[100005],lb[100005];int dfn[1000005],low[1000005];int block[1000005],pa[1000005];int n,m,lo=0,T=0;void add(int x,int y){ lo++; nex[lo]=hed[x]; hed[x]=lo; lb[lo]=y;}void dfs(int x){ dfn[x]=low[x]=++T; q.push(x); for(int i=hed[x];i!=0;i=nex[i]) { if(!dfn[lb[i]]) { dfs(lb[i]); low[x]=min(low[lb[i]],low[x]); } else if(!block[lb[i]]) low[x]=min(low[x],dfn[lb[i]]); } if(low[x]==dfn[x]) { lo++; int xx; while(xx!=x) { xx=q.top();q.pop(); block[xx]=lo; } }}int main(){ int a,b; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d",&a,&b); add(a,b); } lo=0; for(int i=1;i<=n;i++) if(dfn[i]==0) dfs(i); printf("%d",lo); return 0;}
阅读全文
0 0
- 强连通分量模板
- 强连通分量模板
- 强连通分量模板
- 强连通分量 模板
- 强连通分量模板
- 强连通分量模板
- 强连通分量模板
- 【强连通分量模板】
- 【模板】强连通分量
- 强连通分量模板
- 强连通分量Tarjan模板
- 强连通分量(模板)
- Tarjan强连通分量模板
- 强连通分量缩点的模板
- hdu1269 Tarjan强连通分量 模板
- tarjan求强连通分量模板
- 强连通分量-tarjan算法模板详解
- tarjan 求强连通分量模板
- arduino上采集的数据转化为odom
- SpringBoot27-spingboot数据访问-NoSQL(Redis)
- Hololens开发之环境搭建
- 最短路径——迪杰斯坷垃算法(有向图、单源最短路径)
- HDU5952 Counting Cliques 【搜索剪枝】
- 【模板】强连通分量
- 极1s刷Padavan改华硕[N14U N54U]固件
- 百度实时热点原理
- 【UVA 10397 Connect the Campus】& 最小生成树 & Kruskal
- 054 曲率的计算
- 数据结构_循环链表
- SSH简单开发流程
- 调用Weka API,在使用分类器(以随机森林Random Forest为例)的同时使用特征选择方法
- 斐波那契数列(数论+矩阵加速)