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. Java多线程之通过标识关闭线程

    package org.study2.javabase.ThreadsDemo.status; /** * @Auther:GongXingRui * @Date:2018/9/19 * @Descr ...

  2. SpringMVC中对多部件类型解析---文件(图片)上传

    加入上传图片jar包 commons-io-2.4.jar commons-fileupload-1.3.jar 在页面form中提交enctype="multipart/form-data ...

  3. github上传时出现error: src refspec master does not match any解决办法22

    1 error:src refspec master does not match any这个问题,我之前也遇到过,这次又遇到了只是时间间隔比较长了,为了防止以后再遇到类似问题,还是把这个方法简单记录 ...

  4. Spring Boot 构建电商基础秒杀项目 (十) 交易下单

    SpringBoot构建电商基础秒杀项目 学习笔记 新建表 create table if not exists order_info ( id varchar(32) not null defaul ...

  5. 使用styled-components实现CSS in JS

    前面的话 使用jsx语法可以实现HTML in JS,使用svgr可以实现svg in JS,使用styled-components可以实现CSS in JS.这样,使用react开发,就变成了使用J ...

  6. caffe boost cuda __float128 undefined

    转载:https://blog.csdn.net/thesby/article/details/50512886 编译caffe-master时遇到的问题,__float128未定义,使用到cuda版 ...

  7. faster rcnn讲解很细

    https://blog.csdn.net/bailufeiyan/article/details/50749694 https://www.cnblogs.com/dudumiaomiao/p/65 ...

  8. Codeforces#543 div2 B. Mike and Children(暴力?)

    题目链接:http://codeforces.com/problemset/problem/1121/B 题意 给n个数 最多的对数 其中每一对(i,j)的ai+aj都相等(不知道怎么解释.... 判 ...

  9. 在web-inf外面 使用的是绝对路径进行访问 “/”表示访问文件夹 一层一层方式 我们在windos下访问文件夹也是一层一层的访问

  10. Android ProgressDialog 简单实用

    ProgressDialog progressDialog; @SuppressLint("HandlerLeak") Handler handler1 = new Handler ...