POJ1144Network(割边模板题)
来源:互联网 发布:cryengine3 编程语言 编辑:程序博客网 时间:2024/06/07 11:22
Network
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 13771 Accepted: 6257
Description
A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is
possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure
occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.
possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure
occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.
Input
The input file consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
Output
The output contains for each block except the last in the input file one line containing the number of critical places.
Sample Input
55 1 2 3 4062 1 35 4 6 200
Sample Output
12
Hint
You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.
Source
Central Europe 1996
题目大意:根据所给的信息形成一个图,一共有多少个点是割点
解题大意:这道题主要算法在于是否能判断某个点的子节点是否在不经过自己的情况下,到达父节点甚至父节点以上的祖辈节点,这需要我们再从任意一个点开始遍历的时候,用数组存下遍历每个点的时候的时间顺序,根据子节点所能到达的点的时间戳与父节点的时间戳比较判断
#include<iostream> #include<cstdio> #include<stdio.h> #include<cstring> #include<cstdio> #include<climits> #include<cmath> #include<vector> #include <bitset> #include<algorithm> #include <queue> #include<map> #define inf 9999999; using namespace std;/*start:2017/5/7 21:19*//*end:2017/5/7 22:30*/int root, indexx;int low[105], num[105], ans, n;//low[i]表示i这个点能够到达的最小的时间戳,num[i]表示i这个点的编号bool flag[105];vector<int> tu[105];void dfs(int x, int y)//x为子节点,y为父节点{int child, i, k;child = 0;indexx++;low[x] = indexx;//x这个点能够到达的最小的时间戳就是自己本身num[x] = indexx;for (i = 0; i < tu[x].size(); i++){k = tu[x][i];if (num[k] == 0){child++;dfs(k, x);low[x] = min(low[x], low[k]);//若是k这个子节点能够绕过父节点x到达更小的时间戳(时间戳越小,相当于辈分越大)//意味着他这个父节点也能到子节点到的这个最小的时间戳if (x != root&&low[k] >= num[x])//子节点的时间戳若是大于父节点的编号//意味着他只能到比他更小的点,所以这个点可以当作割点{flag[x] = true;}if (x == root&&child == 2)//如果当前点为根节点,要有两个儿子,那么这个点也是割点{flag[x] = true;}}else if (k != y){low[x] = min(low[x], num[k]);}}}int main(){for (;;){int x, y;cin >> n;if (n == 0)break;indexx = 0;ans = 0;memset(tu, 0, sizeof(tu));memset(low, 0, sizeof(low));memset(num, 0, sizeof(num));memset(flag, false, sizeof(flag));for (;;){cin >> x;if (x == 0)break;while (getchar() != '\n'){cin >> y;tu[x].push_back(y);tu[y].push_back(x);}}root = 1;dfs(1, root);for (int i = 1; i <= n; i++){if (flag[i])ans++;}cout << ans << endl;}}
0 0
- POJ1144Network(割边模板题)
- POJ1144Network(求割点模板题)
- poj1144Network(无向图割点数)
- 割点,割边模板
- 割点&割边模板
- 割点 割边 模板
- 我的割边模板HDU 3849
- POJ1144-Network(割顶模板题)
- 【HDU】3452 Bonsai 最小割模板题
- POJ2914 Minimum Cut(最小割模板题)
- hdu 3002 全局最小割模板题
- HDU6214(最小割SAP模板题)
- 割点,桥模板
- 割点模板
- (最小割模板)
- 全局最小割模板
- poj1144 割点模板
- 割点(模板)
- 人人网2017实习笔试-求和A
- CentOS 7.2 安装JDK1.8(rpm版)
- Python自定义豆瓣电影种类,排行,点评的爬取与存储(进阶下)
- 给字符数组赋值的方法
- 微软的React Native热更新
- POJ1144Network(割边模板题)
- XML知识
- 什么是指针函数?什么是函数指针?回答并举例
- android面试题-人事面试宝典二
- 二分查找(源码)
- tensorflow 笔记(0)
- Webpack2入门
- 学习笔记(C基础+进阶)
- Android系统服务注册