poj 1523 SPF
来源:互联网 发布:sql select 多张表 编辑:程序博客网 时间:2024/05/29 16:35
求删掉割点后图变成几个连通分支。
求割点,对每个块上的点进行统计。输出割点存在于几个块就可以了。
#include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <stack>#include <map>#include <set>#include <queue>#include <cstring>#include <algorithm>using namespace std;#define L(t) t<<1#define R(t) t<<1|1#define eps 1e-7typedef long long LL;const int INF=1000000010;const int maxn=1005;const int maxm=1005;const int MOD=1000000007;int head[maxn],next[maxn*3],to[maxn*3];int tot,cnt,top;int dfn[maxn],low[maxn],st[maxn];int block[maxn];bool isGe[maxn];bool node[maxn];void cutBlock(int v){ dfn[v]=low[v]=++cnt; st[++top]=v; int u; for(int i=head[v];i!=-1;i=next[i]) { u=to[i]; if(!dfn[u]) { cutBlock(u); low[v]=min(low[v],low[u]); if(low[u]>=dfn[v]) { isGe[v]=true; while(true) { block[st[top]]++; if(st[top--]==u) break; } block[v]++; } } else { low[v]=min(low[v],dfn[u]); } }}void addEdge(int u,int v){ next[tot]=head[u],to[tot]=v,head[u]=tot++; next[tot]=head[v],to[tot]=u,head[v]=tot++;}int main(){ //freopen("in.txt","r",stdin); int u,v; int T=0; while(scanf("%d",&u),u) { cnt=0,tot=0; memset(isGe,0,sizeof(isGe)); memset(block,0,sizeof(block)); memset(head,-1,sizeof(head)); memset(node,0,sizeof(node)); memset(dfn,0,sizeof(dfn)); scanf("%d",&v); addEdge(u,v); while(scanf("%d",&u),u) { scanf("%d",&v); addEdge(u,v); node[u]=1,node[v]=1; } printf("Network #%d\n",++T); for(int i=1;i<maxn;i++) { top=0; if(!dfn[i]&&node[i]) { cutBlock(i); } } bool pf=1; for(int i=1;i<maxn;i++) { if(isGe[i]&&node[i]&&block[i]>1) { printf(" SPF node %d leaves %d subnets\n",i,block[i]); pf=0; } } if(pf) printf(" No SPF nodes\n"); printf("\n"); }}
- POJ 1523 SPF
- poj 1523 SPF
- POJ 1523 SPF //求割点
- POJ 1523 SPF
- poj 1523 SPF
- poj 1523 SPF
- POJ 1523 SPF 求割点
- POJ 1523 SPF(求割点)
- poj 1523 SPF 求割点
- poj 1523 SPF
- poj 1523 SPF
- POJ 1523 SPF
- poj 1523 spf 求割点
- POJ 1523 SPF
- POJ 1523 SPF
- poj 1523 SPF
- Poj 1523 SPF 关节点
- poj 1523 SPF
- ASCII码排序JAVA实现
- jQuery Ajax事件-ajaxSend(callback)
- 已经显现了出来的飞秋下载
- 使用select函数的TCP和UDP回射服务器程序
- 它们翻滚着的飞秋下载
- poj 1523 SPF
- 神奇的构造代码块
- 做为技术人员为什么要写博客
- Tutorial 14 - Camera Control - Part 1
- Android_ListView_Adapter使用和数据动态加载
- Python挑战的解决方案(1-10)
- 【白话经典算法系列之十七】 数组中只出现一次的数
- 飞鸽传书 桌面上常见的窗口:
- 随机生成四则运算式及答案(含括号)