HLG 1494网络 (求的割点数目)可做模板
2015-08-30 21:24
375 查看
网络 | ||||||
| ||||||
Description | ||||||
一个电话公司建立了一个新的电话网,他们用1——N的整数标记了一些地方,每个地方有唯一的编号,网络中的每条电缆双向连接了两个地方,从每个地方可以通过电缆连接到任意其他的地方,因为它们之间不一定要有直接相连的电缆,可以通过其他的电缆间接连接,有的时候某个地方的电力可能会中断,从而导致这个地方无法被连接,电话公司意识到了某些地方的电力中断可能会导致其他地方也无法互相连接,把这些地方叫做关键点,所以他们决定写一个程序去找到这些地方。 | ||||||
Input | ||||||
每组输入是一个电话网络,每组的第一行是一个整数N<100,表示电话网络连接了N个地点,接下来是不超过N行整数,每行表示第一个整数与后面的整数表示的地点之间有电缆直接相连,每组数据以0结束,输入也以0结束。 | ||||||
Output | ||||||
输出关键点的数量 | ||||||
Sample Input | ||||||
5 5 1 2 3 4 0 6 2 1 3 5 4 6 2 0 0 | ||||||
Sample Output | ||||||
1 2 |
#include<iostream> #include<stdio.h> #include<string.h> #define N 110 using namespace std; int dfn , low ; bool mark , ans ; bool edge ; int cnt, son, n; int min(int a, int b) { return a < b ? a : b; } void unit() { memset(edge, 0, sizeof(edge)); memset(mark, 0, sizeof(mark)); memset(ans, 0, sizeof(ans)); cnt=1; son=0; mark[1]=low[1]=dfn[1]=1; } void dfs(int u) { for(int v=1;v<=n;v++) { if(edge[u][v]) { if(!mark[v]) { mark[v]=1; dfn[v]=low[v]=++cnt; dfs(v); low[u]=min(low[u],low[v]); if(low[v]>=dfn[u]) { if(u!=1) ans[u]=1; else son++; } } else low[u]=min(low[u],dfn[v]); } } return ; } int main() { int i; char str[300]; while(cin >> n) { if(n==0) break; getchar(); unit(); while(true) { gets(str); if(strcmp(str, "0")==0) break; int len=strlen(str); int num=0; for(i=0; str[i]>='0'&&str[i]<='9'; i++) num=num*10+str[i]-'0'; for(;i<len; i++) { int m=0; for(;str[i]>='0'&&str[i]<='9'&&i<len; i++) { m=m*10+str[i]-'0'; } if(m!=0) edge[num][m]=edge[m][num]=1; } } dfs(1); int js=0; for(int j=1; j<=n; j++) js+=ans[j]; if(son>=2) cout << js+1 << endl; else cout << js << endl; } return 0; }
相关文章推荐
- 几句话掌握子网掩码、ip地址、主机号、网络号、网络地址、广播地址
- 《JAVA网络编程》阅读笔记(四)
- TCP的三次握手和四次挥手
- syslog函数详解 http://blog.chinaunix.net/uid-10540984-id-3506091.html
- Android Xutils框架HttpUtil Get请求缓存问题
- Android Xutils框架HttpUtil Get请求缓存问题
- Retrofit 网络请求
- TCP服务器/客户端代码示例
- Liunx学习笔记--基本网络设定(测试内容)
- 九、MDT 2013 Update 1批量部署-第三方PXE无盘网络启动配套使用
- iOS学习总结之网络编程
- Android4.0以上版本Http请求的问题
- Volley理解
- [网络转载 ]LoadRunner技巧之THML与URL两种录制模式分析
- 网络协议
- configure: error: in `/root/httpd-2.2.11/srclib/apr': c
- HTTP API选择WinInet or WinHttp?
- TCP/IP协议详解内容总结(怒喷一口老血)
- 计算机网络知识点
- 强制使用处于TIME_WAIT的TCP状态的socket地址