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. 一、ABP框架框架摘要

    ABP框架几点说明: 一.什么是ABP ABP是一个建立在最新的ASP.NET的MVC和Web API技术的应用框架.它可以很容易地使用依赖注入.日志记录.验证.异常处理.本地化等,也使用流行的框架和 ...

  2. LodopJS代码模版的加载和赋值

    Lodop模版有两种方法,一种是传统的JS语句,可以用JS方法里的eval来执行,一种是文档式模版,是特殊格式的base64码,此篇博文介绍JS模版的加载和赋值.两种模版都可以存入一下地方进行调用,比 ...

  3. Span<T>

    Introduction Span<T> is a new type we are adding to the platform to represent contiguous regio ...

  4. 红米Note 7 Pro在印度首销迅速售罄

    3月13日消息,红米Note 7 Pro在印度率先发售. 小米印度业务负责人Manu Kumar Jain发推特表示,红米Note 7 Pro开售几秒钟就被抢光,我们的工厂正在加班加点工作,全力以赴提 ...

  5. Jquery实现菜单栏

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  6. git 命令使用集锦

    使用git mv重命名文件,而不是delete然后再add文件. git format常用命令: git format-patch -4 //从当前分支最新提交点往下共生成4个补丁 git forma ...

  7. Flask 构建微电影视频网站(三)

    搭建后台页面 视图函数位于admin文件夹下, app/admin/views.py 管理员登录页面搭建 视图函数 @admin.route('/') def index(): return '后台主 ...

  8. 【BZOJ1007】【HNOI2008】水平可见直线 几何 单调栈

    题目大意 给你\(n\)条直线\(y=kx+b\),问你从\(y\)值为正无穷大处往下看能看到那些直线. \(1\leq n\leq 500000\) 题解 如果对于两条直线\(l_i,l_j\),\ ...

  9. 搭建gogs常见问题

    1.无法连接ssh,显示connection refuse. 原因是“custom/conf/app.ini”没有开启ssh功能,改为以下配置就行了  START_SSH_SERVER = true ...

  10. MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.

    转自:https://blog.csdn.net/zhaoqi5705/article/details/12087649?locationNum=15 MySql.Data.MySqlClient.M ...