Transferring Sylla
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3533   Accepted: 988

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 ab. 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 6
0 1
0 2
0 3
1 2
1 3
2 3 4 5
0 1
0 2
0 3
1 2
1 3 7 6
0 1
0 2
0 3
1 2
1 3
2 3 0 0

Sample Output

YES
NO
NO 思路:判断给定图是否为三联通分量;
    以下情况不是:
    1.图不连通
    2.图有割点
    3.删去一个点后存在割点。
   这题我用了读入挂(抄的别人的板子)才过。。。。
代码:
 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int f[];
int index,root,n,m,DEL;
int cnt,Head[],v[maxn],Next[maxn];
void init()
{
cnt=;root=;
memset(Head,-,sizeof(Head));
for(int i=;i<=n;i++){
f[i]=i;
}
} inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
}
void add(int x,int y)
{
cnt++;
v[cnt]=y;
Next[cnt]=Head[x];
Head[x]=cnt; cnt++;
v[cnt]=x;
Next[cnt]=Head[y];
Head[y]=cnt;
} int num[],low[];
bool dfs(int cur,int father)
{
int child=;
index++;
num[cur]=index;
low[cur]=index;
for(int k=Head[cur];k!=-;k=Next[k]){
if(v[k]==DEL){continue;}
// fuck(v[k])
if(num[v[k]]==){
child++;
if(!dfs(v[k],cur)){return false;}
low[cur]=min(low[cur],low[v[k]]);
if(cur!=root&&low[v[k]]>=num[cur]){
return false;
}
if(cur==root&&child==){
return false;
}
}
else if(v[k]!=father){
low[cur]=min(low[cur],num[v[k]]);
}
}
return true;
} bool solve()
{
memset(num,,sizeof(num));
memset(low,,sizeof(low));
root=;
DEL=;
if(!dfs(,root)){return false;}
root=;
for(int i=;i<=n;i++){
memset(num,,sizeof(num));
memset(low,,sizeof(low));
DEL=i;
if(!dfs(,root)){
// cout<<i<<endl;
return false;
}
}
return true;
} int getf(int x)
{
if(f[x]==x){return x;}
return f[x]=getf(f[x])
;} bool Merge(int x,int y)
{
int s1=getf(x);
int s2=getf(y);
if(s1!=s2){
f[s1]=s2;
return true;
}
return false;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF&&n&&m){
init();
int snum = ;
for(int i=;i<=m;i++){
int x,y;
scan_d(x);scan_d(y);
add(x+,y+);
if(Merge(x+,y+)){
snum++;
}
}
if(snum!=n-){printf("NO\n");continue;}
memset(num,,sizeof(num));
memset(low,,sizeof(low));
root=;
DEL=;
if(!dfs(,root)){printf("NO\n");continue;} if(solve()){printf("YES\n");}
else printf("NO\n"); } return ;
}

POJ 3713 Transferring Sylla (三联通分量)的更多相关文章

  1. POJ 3713 Transferring Sylla (三连通图)

    [题目链接] http://poj.org/problem?id=3713 [题目大意] 给出一个图判断是不是三连通图,三连通图的意思是对于图中任意两点, 至少有三条路是可以相互连通的. [题解] 我 ...

  2. POJ 3713 Transferring Sylla【Tarjan求割点】

    题意:给出一个无向图,判断是否任意两点间都存在至少3条互相独立的路,独立指公共顶点只有起点和终点.算法:枚举每个点,删去后用Tarjan判断图中是否存在割点,如果存在则该图不满足三连通性.Tarjan ...

  3. POJ 2186-Popular Cows (图论-强联通分量Korasaju算法)

    题目链接:http://poj.org/problem?id=2186 题目大意:有n头牛和m对关系, 每一对关系有两个数(a, b)代表a牛认为b牛是“受欢迎”的,且这种关系具有传递性, 如果a牛认 ...

  4. POJ 2186 Popular Cows(强联通分量)

    题目链接:http://poj.org/problem?id=2186 题目大意:    每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种 ...

  5. POJ 3177 Redundant Paths 双联通分量 割边

    http://poj.org/problem?id=3177 这个妹妹我大概也曾见过的~~~我似乎还没写过双联通分量的blog,真是智障. 最少需要添多少条边才能使这个图没有割边. 边双缩点后图变成一 ...

  6. POJ 3694Network(Tarjan边双联通分量 + 缩点 + LCA并查集维护)

    [题意]: 有N个结点M条边的图,有Q次操作,每次操作在点x, y之间加一条边,加完E(x, y)后还有几个桥(割边),每次操作会累积,影响下一次操作. [思路]: 先用Tarjan求出一开始总的桥的 ...

  7. POJ 3352 Road Construction 双联通分量 难度:1

    http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...

  8. poj Transferring Sylla(怎样高速的推断一个图是否是3—连通图,求割点,割边)

    Transferring Sylla 首先.什么是k连通图? k连通图就是指至少去掉k个点使之不连通的图. 题目: 题目描写叙述的非常裸.就是给你一张图要求你推断这图是否是3-连通图. 算法分析: / ...

  9. poj 3180 The Cow Prom(强联通分量)

    http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

随机推荐

  1. shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较

    这里以简单的登陆为例子 控制器对应的登陆方法: @RequestMapping(value = "/login", method = RequestMethod.GET) publ ...

  2. jdbc工具类2..0

    一.创建外部文件 url=jdbc:mysql:///qy66 use=root password=root driver=com.mysql.jdbc.Driver 二.创建工具类 package ...

  3. Java使用RabbitMQ之消息确认(confirm模板)

    RabbitMQ生产者消息确认Confirm模式,分为普通模式.批量模式和异步模式,本次举例为普通模式. 源码: package org.study.confirm4; import com.rabb ...

  4. Python——数组模块(array)

    一.模块说明 array模块是python中实现的一种高效的数组存储类型.它和list相似,但是所有的数组成员必须是同一种类型,在创建数组的时候,就确定了数组的类型. 二.代码

  5. Python学习之路——Day02

    今日内容: 1.编程语言介绍(***) 2.python介绍(***) 3.安装cpython解释器(多个版本)(****) 4.运行python程序的两种方式(****) 4.1 交互式 4.2 命 ...

  6. HttpWebRequest using Basic authentication

    System.Net.CredentialCache credentialCache = new System.Net.CredentialCache(); credentialCache.Add( ...

  7. CSS3 flexbox 布局 ---- flex项目属性介绍

    现在介绍用在flex项目上的css 属性,html结构还是用ul, li 结构,不过内容改成1,2,3, 样式的话,直接把给 ul 设display:flex 变成flex 容器,默认主轴的方向为水平 ...

  8. PHP——敏感词过滤

    前言 如果可以用第三方的话,那么你是幸运的,因为现在这种敏感词过滤,敏感图片,敏感语音过滤的第三方服务还是挺多的 敏感词过滤 核心代码 利用PHP内置的三个函数 array_combine() | a ...

  9. Codeforces300 F. A Heap of Heaps

    Codeforces题号:#300F 出处: Codeforces 主要算法:树状数组/线段树 难度:4.6 思路分析: 在没看到数据范围之前真是喜出望外,直到发现O(n^2)会被卡…… 其实也不是特 ...

  10. bzoj 2429: [HAOI2006]聪明的猴子 (最小生成树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2429 思路:就是找最小生成树最大的一条边,最小生成树的性质,最后加入的那条边就是最大的 实现 ...