Poj 1523 SPF 关节点
2013-08-12 16:32
85 查看
经典的关节点例题,要注意只有1个点的情况
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; int org[1001][1001],n; bool ok; int dph[1001],low[1001],vis[1001],Ans[1001]; void dfs(int u,int d)//Tarjan { dph[u]=low[u]=d; vis[u]=1; int ans=0; for(int v=1;v<=n;v++) { if(!org[u][v])continue; if(vis[v]) { low[u]=min(low[u],dph[v]); } else { dfs(v,d+1); if(low[v]>=dph[u])ans++; low[u]=min(low[u],low[v]); } } if(u==1&&ans>=1)Ans[u]=ans-1; else Ans[u]=ans; } int main() { int a,b,T=0; while(~scanf("%d",&a)&&a) { n=0; scanf("%d",&b); memset(org,0,sizeof(org)); if(T)puts(""); T++; org[a][b]=org[b][a]=1; n=max(n,max(a,b)); while(~scanf("%d",&a)&&a) { scanf("%d",&b); org[a][b]=org[b][a]=1; n=max(n,max(a,b)); } ok=0; memset(Ans,0,sizeof(Ans)); memset(vis,0,sizeof(vis)); printf("Network #%d\n",T); dfs(1,1); for(int i=1;i<=n;i++) { if(Ans[i]) ok=1, printf(" SPF node %d leaves %d subnets\n",i,Ans[i]+1); } if(!ok)printf(" No SPF nodes\n"); } }
相关文章推荐
- poj 1523 SPF 无向图关节点
- poj 1523 SPF 无向图关节点
- Zoj 1119 POJ 1523 SPF 求关节点及删除关节点会出现多少个连通分量 Tarjan算法
- POJ 1523-SPF(Tarjan算法-关节点)
- poj 1523 SPF(模板题)(Tarjan 关节点的朴素算法)
- poj 1523 关节点
- poj1523 SPF 无向连通图 求割点 关节点 tarjan算法
- POJ 1523 SPF (无向图求割点 tarjan算法)
- POJ1523--SPF--tarjan--割点--分块
- 【Q】【poj 1144】【poj 1523】
- POJ 1523 SPF (割点 && 点双连通分量)
- POJ - 1523 SPF
- poj 1523 SPF
- POJ 1523 SPF【割点】
- poj1523割点模板
- POJ 1523 SPF
- POJ - 1523 SPF(割点)
- poj 1947 树形dp(得到含P个节点联通块的最小切边数)
- POJ 1523——Tarjan + 计算删除割点后的连通分支数
- POJ-1523 SPF 无向图求割点