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. Yii2控制台命令

    Yii2控制台表格输出: 例如: $in_sheet_number_queue = []; $wms_material_in_sheet_list = \core\models\WmsMaterial ...

  2. nginx worker_processes 配置

    搜索到原作者的话:As a general rule you need the only worker with large number ofworker_connections, say 10,0 ...

  3. fiddler学习笔记2 字段说明;移动设备、解密证书

    # :           抓取顺序从1开始递增 result:    http 请求状态 protocol:   请求使用的协议如:http https ftp Host:         请求地址 ...

  4. LodopFuncs.js和CLodopFuncs.js区别和联系

    所在位置:LodopFuncs.js可以在官网下载中心综合版里下载到.CLodopfuncs.js在C-Lodop服务缓存中,C-Lodop启动的时候才能访问到. 需不需要下载放置到项目里:(客户端本 ...

  5. 检测某一目录下md5相同的文件

    import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; import jav ...

  6. [Codeforces235D]Graph Game——概率与期望+基环树+容斥

    题目链接: Codeforces235D 题目大意:给出一棵基环树,并给出如下点分治过程,求点数总遍历次数的期望. 点分治过程: 1.遍历当前联通块内所有点 2.随机选择联通块内一个点删除掉 3.对新 ...

  7. PHP——emjoin表情存入数据库

    前言 还有一种解决的方法是更改数据库,这里就不写了,这里直接对emoji进行转码 代码 mb_strlen() | strlen() | rawurlencode() | rawurldecode() ...

  8. BZOJ3105 新Nim游戏 【拟阵】

    题目分析: 我不知道啥是拟阵啊,但有大佬说线性基相关的都是拟阵,所以直接贪心做了. 题目代码: #include<bits/stdc++.h> using namespace std; ; ...

  9. git回滚部分文件到某个版本

    reset 命令只能将整个版本的代码一起回滚,需要使用checkout 命令,可以还原部分文件到某一版本 格式为:git checkout [<branch>] [file] 1.首先使用 ...

  10. 【比赛】NOIP2018 货币系统

    可以发现最后的集合一定是给定集合的子集 所以就变成了裸的背包嘛,对于每个数判断它能不能被其它数表示出来,如果可以,就表示这个数是没用的,可以去掉 #include<bits/stdc++.h&g ...