poj 1523 SPF
来源:互联网 发布:淘宝客推广佣金设置 编辑:程序博客网 时间:2024/05/21 19:36
SPF
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 4263 Accepted: 1967
Description
Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.
Node 3 is therefore a Single Point of Failure (SPF) for this network. Strictly, an SPF will be defined as any node that, if unavailable, would prevent at least one pair of available nodes from being able to communicate on what was previously a fully connected network. Note that the network on the right has no such node; there is no SPF in the network. At least two machines must fail before there are any pairs of available nodes which cannot communicate.
Node 3 is therefore a Single Point of Failure (SPF) for this network. Strictly, an SPF will be defined as any node that, if unavailable, would prevent at least one pair of available nodes from being able to communicate on what was previously a fully connected network. Note that the network on the right has no such node; there is no SPF in the network. At least two machines must fail before there are any pairs of available nodes which cannot communicate.
Input
The input will contain the description of several networks. A network description will consist of pairs of integers, one pair per line, that identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2 1 specify the same connection. All node numbers will range from 1 to 1000. A line containing a single zero ends the list of connected nodes. An empty network description flags the end of the input. Blank lines in the input file should be ignored.
Output
For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.
The first network in the file should be identified as "Network #1", the second as "Network #2", etc. For each SPF node, output a line, formatted as shown in the examples below, that identifies the node and the number of fully connected subnets that remain when that node fails. If the network has no SPF nodes, simply output the text "No SPF nodes" instead of a list of SPF nodes.
The first network in the file should be identified as "Network #1", the second as "Network #2", etc. For each SPF node, output a line, formatted as shown in the examples below, that identifies the node and the number of fully connected subnets that remain when that node fails. If the network has no SPF nodes, simply output the text "No SPF nodes" instead of a list of SPF nodes.
Sample Input
1 25 43 13 23 43 501 22 33 44 55 101 22 33 44 66 32 55 100
Sample Output
Network #1 SPF node 3 leaves 2 subnetsNetwork #2 No SPF nodesNetwork #3 SPF node 2 leaves 2 subnets SPF node 3 leaves 2 subnets
代码:
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int MAXN = 1010 ;int g[MAXN][MAXN];int dfn[MAXN] , low[MAXN] , stack[MAXN] ;int top , idx , cnt ;int bcc[MAXN][MAXN] ;int visit[MAXN];int n;void init(){ for(int i=1; i<n; i++) for(int j=1; j<n; j++) g[i][j] = 0 ; memset(visit , 0 ,sizeof(visit));}void tarjin(int x, int pre){ dfn[x] = low[x] = ++idx ; stack[++top] = x ; for(int i=1; i<n; i++) { if(i==pre || g[x][i]==0||visit[i]==0) continue ; if( dfn[i]==-1 ) { tarjin(i,x) ; if( low[i] < low[x]) low[x] = low[i] ; if( low[i] >= dfn[x] ) { ++ cnt ; int u ; do { u = stack[top--] ; bcc[cnt][u] = 1 ; } while( u!=i ) ; bcc[cnt][x] = 1 ; } } else if( dfn[i]<low[x]) low[x] = dfn[i] ; }}void solve(){ idx = top = cnt = 0 ; memset(dfn, -1, sizeof(dfn)); memset(bcc , 0 , sizeof(bcc)); for(int i=1; i<n; i++) { if(visit[i]==0) continue; if( dfn[i] == -1) { tarjin(i , -1); } }}int main(){ int a,b; int cas=0; while(scanf("%d",&a),a) { cas++; init(); scanf("%d",&b); visit[a]=1; visit[b]=1; g[a][b]=g[b][a]=1; while(scanf("%d",&a),a!=0) { visit[a]=1; scanf("%d",&b); visit[b]=1; g[a][b]=g[b][a]=1; } n=MAXN; solve(); printf("Network #%d\n",cas); bool flag=1; int c=0; for(int i=1;i<n;i++) { c=0; if(visit[i]==1) { for(int j=1;j<=cnt;j++) { if(bcc[j][i]==1) c++; } } if(c>1) { flag=0; printf(" SPF node %d leaves %d subnets\n",i,c); } } if(flag) { printf(" No SPF nodes\n"); } printf("\n"); } return 0;}
- 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
- fscanf rewind
- file_operation(文件操作)file(文件)inode(节点)三者比较
- 将exe文件剥离出swf文件
- 诗意美句
- 杀生 影评
- poj 1523 SPF
- Integer与int的区别
- Spring基本知识——入门1
- JEECG V3版本组合查询实现方法
- 【转】中国电信韦乐平畅谈去电信化:摆脱禁锢 孕育新生
- iOS学习笔记10(1)—GCD介绍(一): 基本概念和Dispatch Queue
- 公钥和私钥
- 中英文字符串截取
- osg设置透明