poj1523(割点)
来源:互联网 发布:刚开的淘宝卖什么 编辑:程序博客网 时间:2024/05/22 00:43
1.思路参考刘汝佳的算法艺术与信息学竞赛。
2.代码。
#include<cstdio>#include<iostream>using namespace std;// freopen("data.in","r",stdin);#include<cstring>#define N 1005bool G[N][N];int _V;int root;bool vis[N];int deep[N],ancestor[N];bool cutP[N];//int son[N];int cutE[N][N];void init(){ memset(G,0,sizeof(G)); memset(cutP,0,sizeof(cutP)); // memset(son,0,sizeof(son)); memset(deep,-1,sizeof(deep)); memset(vis,0,sizeof(vis)); _V=2; root=1;}void dfs(int u,int father,int d){ deep[u]=ancestor[u]=d; int son=0; for(int v=1; v<=_V; v++) { if(G[u][v]) { if(deep[v]==-1) { son++; dfs(v,u,d+1); ancestor[u]=ancestor[u]>ancestor[v]?ancestor[v]:ancestor[u]; } else if(v!=father) { ancestor[u]=ancestor[u]>deep[v]?deep[v]:ancestor[u]; } } } if(u==root) { if(son>1)cutP[root]=true; else cutP[root]=false; } else if(ancestor[u]>=deep[father])// { cutP[father]=true; cutE[father][u]=true; }}void output(int Case){ printf("Network #%d\n",Case); bool exist=false; for(int u=1; u<=_V; u++) { if(cutP[u]) { exist=true; int branch; if(u==1)branch=0; else branch=1; bool f=false; for(int v=1;v<=_V;v++) { if(G[u][v]) { if(ancestor[v]>deep[u])branch++; if(ancestor[v]==deep[u])f=true; } } printf(" SPF node %d leaves %d subnets\n",u,branch+f); } } if(!exist)printf(" No SPF nodes\n"); cout<<endl;}int main(){ // freopen("data.in","r",stdin); int Case=1; int u,v; while(~scanf("%d",&u)&&u) { init(); scanf("%d",&v); vis[u]=vis[v]=G[u][v]=G[v][u]=true; while(~scanf("%d",&u)&&u) { scanf("%d",&v); G[u][v]=G[v][u]=true; if(!vis[u]) { vis[u]=true; _V++; } if(!vis[v]) { vis[v]=true; _V++; } } dfs(1,0,0); output(Case); Case++; } return 0;}
- poj1523(割点)
- poj1523割点&&块
- POJ1523 SPF 割点
- poj1523(割点)
- poj1523 割点+连通分量
- poj1523.SPF(割点模板)
- poj1523赤裸裸的割点
- [学习][poj1523]割点 SPF
- POJ1523--SPF--tarjan--割点--分块
- poj1523 求割点 及 该割点 可以 把该图分成几个连通分量
- poj1523—SPF(tarjan算法求无向图中所有的割点)
- POJ1523.SPF——无向图的割点,并求连通分支数(tarjan算法)
- poj1523[割顶&连通分支数]
- poj1523 最小割+并查集
- poj1523
- poj1523
- poj1523
- poj1523
- zoj 1010
- 想成为代理商需要办什么样的营业执照,如何办手续,最低注册资金要多少?
- 用C#实现HTTP协议下的多线程文件传输
- WEB前台架构部分经验总结------第一章、浅谈页面设计
- hgnkj;pko';'o;'ip'po
- poj1523(割点)
- poj 3630 Phone List
- 如何在自己网站加上视频直播功能(搭建视频直播网站)
- hdu1061
- WEB前台架构教程(原创)第二章(第一节PS切图规划)
- Calculate distance based on GPS data (latitude and longitude)
- 近来在听数电与模电的课
- 很简单的过滤特殊字符的函数
- Dispatcher initialization failed