POJ 1144 && UVA 315 ——无向连通图求割顶
来源:互联网 发布:数据库排序 编辑:程序博客网 时间:2024/06/08 15:56
Network
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 8111 Accepted: 3823
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 <cstdio>#include <cmath>#include <algorithm>#include <iostream>#include <cstring>#include <map>#include <string>#include <stack>#include <cctype>#include <vector>#include <queue>#include <set>#include <utility>#include <cassert>using namespace std;///#define Online_Judge#define outstars cout << "***********************" << endl;#define clr(a,b) memset(a,b,sizeof(a))#define lson l , mid , rt << 1#define rson mid + 1 , r , rt << 1 | 1#define mk make_pair#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)const int MAXN = 100 + 50;const int sigma_size = 26;const long long LLMAX = 0x7fffffffffffffffLL;const long long LLMIN = 0x8000000000000000LL;const int INF = 0x7fffffff;const int IMIN = 0x80000000;#define eps 1e-8const int MOD = (int)1e9 + 7;typedef long long LL;const double PI = acos(-1.0);typedef double D;typedef pair<int , int> pi;///#pragma comment(linker, "/STACK:102400000,102400000")vector<int> edge[MAXN];int cut[MAXN];//struct NODE//{// int num;//}node [MAXN];void add_edge(int u , int v){ edge[u].push_back(v); edge[v].push_back(u);}int dfs_time , ans , root;int pre[MAXN] , low[MAXN];void tarjan(int u, int fa){ pre[u] = low[u] = dfs_time++; int child = 0; FOR(i , 0, edge[u].size()) { int v = edge[u][i]; if(pre[v] == -1) { tarjan(v , u); child ++; if(low[u] > low[v])low[u] = low[v]; if(low[v] >= pre[u]) cut[u] = 1; } else if(low[u] > pre[v] && fa != -1)low[u] = pre[v]; } if(fa == -1 && child == 1)cut[u] = 0; if(cut[u]) ans ++;}int main(){// freopen("heritage.in","r",stdin);// freopen("heritage.out","w",stdout); int n; while(~scanf("%d" , &n) , n) { for(int i = 1; i <= n; i ++) edge[i].clear(); int u , v; while(scanf("%d", &u), u) { while(getchar() != '\n') { scanf("%d", &v); add_edge(u , v); } } clr(pre , -1); clr(cut , 0); dfs_time = 1; ans = 0; tarjan(1, -1);// puts("");// for(int i = 1; i <= n; i ++) printf("%d ", pre[i]);// puts("");// for(int i = 1; i <= n; i ++) printf("%d ", low[i]); printf("%d\n" , ans); } return 0;}
- POJ 1144 && UVA 315 ——无向连通图求割顶
- poj 1144 Network 无向连通图求割点
- POJ 1144 Network(无向图连通分量求割点)
- 图论——寻找无向连通图割点算法
- 无向连通图中求割点集
- poj 1966 无向图的点连通度
- poj 3713(判断无向图是否三连通)
- POJ 1523 SPF(无向图连通分量求割点)
- POJ 3352 Road Construction(无向连通图)
- POJ 2762 判断无向图的弱连通
- POJ 1966 求无向图点连通度
- POJ 1515 无向连通图定向边改造为强连通 边双连通
- 无向图连通分支
- 求无向连通图的最小生成树算法——Prim与Kruska
- POJ1966.Cable TV Network——无向图的点连通度
- 【Tinsen】A1493. 城市规划【简单无向连通图个数——NTT】
- 并查集——求无向图的所有连通子图
- UVA 315 Network(无向图求割点)
- ACM POJ 3020 Antenna Placement 二分匹配
- 第二章
- 用递归计算C(m,n)
- 分桶法和平方分割(对区间的操作)
- Ajax的工作原理
- POJ 1144 && UVA 315 ——无向连通图求割顶
- UNIX网络编程初步
- JS冒泡事件解决方案
- 电子研发联盟-多功能数字调频收音机
- Sprite Kit 动作系统
- android开发出现R cannot be resolved to a variable 问题解决办法之一
- TTL电平,CMOS电平
- jstl 获取Parameter参数 , switch使用
- 在C#中利用SQL语句与数据库进行操作