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. solr配置ik中文分词(二)

    上一篇文章主要介绍了solr的安装与配置,这篇文章主要记录如何使用ik分词器对中文进行分词. 步骤: 1.下载ik分词jar包:ik-analyzer-solr5-5.x.jar. 2.将下载的jar ...

  2. HTTP协议 - 使用php模拟get/post请求

    首先 有个疑问, 是不是只有浏览器才能发送http 请求? 答案肯定是错的,第一篇就说了,http是由请求行,请求头,请求主体三个部分组成,那么我们可不可以用代码来模拟一下get和post请求呢: 首 ...

  3. 手机连接WiFi有感叹号x怎么回事?如何消除手机WiFi感叹号?

    经过多年的革新,现在的安卓系统已经非常优秀了,某些程度已经超越iOS,卡顿和耗电也不再是安卓系统的代名词了.而为了体验到最优秀的安卓系统,不少人都会购买海外的手机,因为海外手机的安卓系统都比较精简,非 ...

  4. How to remove unwant Internet Explorer Context Menu

    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt

  5. Nginx websocket反向代理

    L:106 现在主流的反向代理,通过长链接可以从服务器推送数据到页面 升级成websocket反向代理必须根据上面的配置做配置 缺点无法多路复用,也就是没办法并行 我们测试下Websocket反向代理 ...

  6. JarvisOJ Basic 熟悉的声音

    两种元素,还有声音,想到了莫尔斯电码,解码得到 jbluwewnz 提交,发现不对,觉得应该是有实际意义的东西,实在想不到还能怎么解,就去看了题解. 发现这个还可以再套一个凯撒密码,就拿python写 ...

  7. Tyche 2317 Color

    题目大意:有三个人alice,bob,yazid,三种颜色red,blue,green,每个人对应一种颜色. [name] is [color]. Yazid会做以下操作: 1 将三个句子连在一起 2 ...

  8. LIRE图片识别搜索demo--Ubuntu开发

    Ubuntu安装shadowsocks客户端/服务端教程 1.安装shadowsocks sudo apt-get update sudo apt-get install python-pip sud ...

  9. CentOS6.5内核编译

    内核源码包下载地址,戳我 1.准备并解压内核安装包:linux-4.14.6.tar.xz # .tar.xz -C /usr/src/ # cd /usr/src/linux- #查看linux-目 ...

  10. kubernetes ceph-rbd挂载步骤 类型storageClass

    由于kubelet本身并不支持rbd的命令,所以需要添加一个kube系统插件: 下载插件 quay.io/external_storage/rbd-provisioner 下载地址: https:// ...