POJ--1523 SPF(割点)
来源:互联网 发布:烟台淘宝店托管 编辑:程序博客网 时间:2024/05/01 07:48
原题链接
SPF
Time Limit: 1000MS
Memory Limit: 10000KTotal Submissions: 7735
Accepted: 3514
Memory Limit: 10000KTotal Submissions: 7735
Accepted: 3514
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 <cstdio>#include <algorithm>#include <cstring>#include <vector>#define maxn 1005using namespace std;typedef long long ll;vector<int> v[maxn];int pre[maxn], is[maxn], cnt;int dfs(int i, int f){pre[i] = ++cnt;int low = pre[i], child = 0;for(int j = 0; j < v[i].size(); j++){int h = v[i][j];if(pre[h] == 0){++child;int k = dfs(h, i);if(k >= pre[i]) is[i]++;low = min(low, k);}else if(pre[h] < low) low = pre[h];}if(f == -1 && child <= 1) is[i] = 0;return low;}int main(){//freopen("in.txt", "r", stdin);int n, m, cas = 0;while(scanf("%d", &n) && n){for(int i = 1; i <= 1000; i++) v[i].clear(); scanf("%d", &m);v[n].push_back(m);v[m].push_back(n);while(scanf("%d", &n) && n){scanf("%d", &m);v[n].push_back(m);v[m].push_back(n);}for(int i = 1; i <= n; i++) v[i].clear();memset(pre, 0, sizeof(pre));memset(is, 0, sizeof(is));cnt = 0;dfs(1, -1);printf("Network #%d\n", ++cas);int sign = 0;if(is[1]){ sign = 1; printf(" SPF node %d leaves %d subnets\n", 1, is[1]); }for(int i = 2; i <= 1000; i++) if(is[i]){ printf(" SPF node %d leaves %d subnets\n", i, is[i]+1); sign = 1; } if(sign == 0) puts(" No SPF nodes");puts("");}return 0;}
0 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(割点 + tarjan算法)
- TOJ 2018 POJ 1523 SPF / 割点
- POJ 1523 SPF(割点)
- POJ-1523 SPF (割点[Tarjan])
- POJ 1523 SPF (割点)
- POJ 1523 SPF 割边与割点
- POJ 1523 SPF(割点所割连通分量数)
- POJ 1523 SPF(割点所割连通分量数)
- POJ 1523 SPF(割点所割连通分量数)
- POJ 1523 SPF (割顶 点双连通分量)
- 使用mycat 读写分离mysql
- 笨小熊
- php的运行方式及vc6和vc9,ts和nts区别
- 拼图-- 中国版的Bootstrap
- 架构师和程序员的区别
- POJ--1523 SPF(割点)
- Android中利用Handler实现图片轮播 ,示例+ 代码
- 疯狂java讲义学习数据类型问题及心得
- 用Android Studio的教大家做gif的方法
- Javascript 严格模式详解
- PL/SQL Developer 免安装步骤
- android中像素单位dp、px、pt、sp的比较
- AOP编程
- 让您的Xcode键字如飞