poj 1523 SPF 无向图关节点
来源:互联网 发布:极光网络魔戒世界礼包 编辑:程序博客网 时间:2024/06/10 16:34
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;const int N=1000+5;int g[N][N],vis[N],low[N],dfn[N],sub[N],dep,n,son;void dfs(int u){ for(int v=1;v<=n;v++) { if(g[u][v]) { if(!vis[v]) { vis[v]=1; dep++; dfn[v]=low[v]=dep; dfs(v); low[u]=min(low[u],low[v]); if(low[v]>=dfn[u]) { if(u==1) son++; else sub[u]++; } } else low[u]=min(low[u],dfn[v]); } }}int main(){ int i,j,u,v,flag,cas=0; while(~scanf("%d",&u)) { n=0; n=max(n,u); if(u==0) break; memset(g,0,sizeof(g)); scanf("%d",&v); n=max(n,v); g[u][v]=g[v][u]=1; while(~scanf("%d",&u)) { if(u==0) break; n=max(n,u); scanf("%d",&v); n=max(n,v); g[u][v]=g[v][u]=1; } memset(vis,0,sizeof(vis)); memset(sub,0,sizeof(sub)); dep=1; son=0; dfn[1]=low[1]=vis[1]=1; dfs(1); if(son>1) sub[1]=son-1; flag=0; if(cas>0) printf("\n"); printf("Network #%d\n",++cas); for(i=1;i<=n;i++) { //printf("%d\n",sub[i]); if(sub[i]) { flag=1; printf(" SPF node %d leaves %d subnets\n",i,sub[i]+1); } } if(!flag) printf(" No SPF nodes\n"); } return 0;}
0 0
- poj 1523 SPF 无向图关节点
- poj 1523 SPF(无向图求关节点)
- Poj 1523 SPF 关节点
- 【连通图|关节点】POJ-1523 SPF
- poj1523 SPF 无向连通图 求割点 关节点 tarjan算法
- poj 1523 SPF (无向图 求割项)
- POJ 1523 SPF(无向图连通分量求割点)
- POJ 1523 SPF 无向图求割点
- poj 1523 SPF 无向图求割点
- POJ 1523 SPF (无向图求割点)
- POJ 1523-SPF(Tarjan算法-关节点)
- POJ 1523 SPF 无向图求割点和块
- POJ 1523 SPF (无向图求割点 tarjan算法)
- POJ 1523 SPF(无向图求割点,去割点形成子图数)
- POJ 1523 SPF Tarjan求无向图割点
- poj 1523 SPF(模板题)(Tarjan 关节点的朴素算法)
- poj 1523 SPF(无向图点的连通性问题)
- 求无向图的关节点算法
- Callable接口与Runnable接口的区别
- MySQLdb导入失败
- java -jar classpath心得
- iOS Auto Layout文章总结
- 基于PL/SQL的数据库备份方法
- poj 1523 SPF 无向图关节点
- Python+OpenCV学习(4)---图像梯度及边缘检测
- 阿里2015校招研发面试经验分享(已经拿到阿里意向书)
- PHP彩信接口开发经验及具体开发实现
- UVA 1626 区间DP
- 输入名字显示其电话号码
- Android Material Design知识汇总
- iOS远程推送
- 全双工 半双工 单工 通信,同步和异步(待续)