poj 3713(判断无向图是否三连通)
来源:互联网 发布:lms软件 编辑:程序博客网 时间:2024/05/20 22:37
Description
After recapturing Sylla, the Company plans to establish a new secure system, a transferring net! The new system is designed as follows:
The Company staff choose N cities around the nation which are connected by "security tunnels" directly or indirectly. Once a week, Sylla is to be transferred to another city through the tunnels. As General ordered, the transferring net must reach a certain security level that there are at least 3 independent paths between any pair of cities a, b. When General says the paths are independent, he means that the paths share only a and b in common.
Given a design of a transferring net, your work is to inspect whether it reaches such security level.
Input
The input consists of several test cases.
For each test case, the first line contains two integers, N ≤ 500 and M ≤ 20000. indicating the number of cities and tunnels.
The following M lines each contains two integers a and b (0 ≤ a, b < N), indicating the city a and city b are connected directly by a tunnel.
The input ends by two zeroes.
Output
For each test case output "YES" if it reaches such security level, "NO" otherwise.
Sample Input
4 60 10 20 31 21 32 34 50 10 20 31 21 37 60 10 20 31 21 32 30 0
Sample Output
YESNONO
Source
#include<cstdio>using namespace std;const int mm=44444;const int mn=555;int t[mm],p[mm];int h[mn],dfn[mn],low[mn],du[mn];int i,j,k,n,m,idx;bool dfs(int u,int fa){ dfn[u]=low[u]=++idx; for(int i=h[u],v,son=0;i>=0;i=p[i]) if(!dfn[v=t[i]]) { ++son; if(dfs(v,u))return 1; if(fa==-1&&son>1||fa!=-1&&dfn[u]<=low[v])return 1; if(low[u]>low[v])low[u]=low[v]; } else if(v!=fa&&low[u]>dfn[v])low[u]=dfn[v]; return 0;}bool tarjan(){ int i,j,k; for(i=0;i<n;++i) if(du[i]<3)return 0; for(i=0;i<n;++i) { for(j=idx=0;j<n;++j)dfn[j]=0; dfn[i]=n+n; for(j=k=0;j<n;++j) if(!dfn[j]) { if(++k>1)return 0; if(dfs(j,-1))return 0; } } return 1;}int main(){ while(scanf("%d%d",&n,&m),n+m) { for(i=k=0;i<n;++i)h[i]=-1,du[i]=0; while(m--) { scanf("%d%d",&i,&j); t[k]=j,p[k]=h[i],h[i]=k++; t[k]=i,p[k]=h[j],h[j]=k++; ++du[i],++du[j]; } puts(tarjan()?"YES":"NO"); } return 0;}
- poj 3713(判断无向图是否三连通)
- 判断无向图G是否连通
- 数据结构判断无向图是否为连通
- 使用并查集判断无向图是否连通
- 通过DFS和BFS判断无向图是否连通
- POJ 2762 判断无向图的弱连通
- eoj 1816. 连通(无向图是否连通判定)
- 判断无向图是否有回路
- 判断无向图是否存在环
- 判断无向图是否有环
- 判断无向图是否有回路
- 无向图判断是否存在环
- 判断无向图是否是一棵树
- 判断无向图是否是树
- 判断无向图是否有环
- 无向图判断是否有环
- cf 659E(强连通分量,判断无向图是否成环,拓扑排序思想)
- POJ2762(判断无向图的弱连通)
- 让Python在Android系统上飞一会儿
- JAVA TCP 服务端 程序代码
- 句柄与重定向
- Oracle中日期函数的使用
- 嵌入式Linux操作系统
- poj 3713(判断无向图是否三连通)
- opencv2.0移植过程中zlib,jpeg,png库的交叉编译
- boa-0.94在power-linux上的移植
- ViewFlipper的使用
- matlab安装时正常,但启动时出错
- Android 应用程序快速启动的秘诀
- IT圈,有哪些经常读错?
- dspace的中文分支NTUR
- QString 与中文问题