POJ3713-Transferring Sylla

来源:互联网 发布:代言宝无水印版源码 编辑:程序博客网 时间:2024/06/09 18:55

Transferring Sylla
Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 2906 Accepted: 802

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 60 10 20 31 21 32 34 50 10 20 31 21 37 60 10 20 31 21 32 30 0

Sample Output

YESNONO

Source

POJ Founder Monthly Contest – 2008.12.28, Dagger


题意:给你一个图,判断这个图是不是3连通图(k连通图就是指至少去掉k个点使之不连通的图)
解题思路:枚举两个点,删掉,看剩下的图是否连通,但这样做超时。可以优化为:枚举删去一个点,看是否还存在割点,如果存在割点,则不是3连通图


#include <iostream>  #include <cstdio>  #include <string>  #include <cstring>  #include <algorithm>  #include <queue>  #include <vector>  #include <set>  #include <stack>  #include <map>  #include <climits>  #include <bitset>  using namespace std;#define LL long long  const int INF = 0x3f3f3f3f;const int N = 1010;int s[N], nt[2 * N*N], e[2 * N*N];int n, son, m;int subnet[N], dfn[N], low[N], tmpdfn;int vis[N];void init(){tmpdfn = 1, son = 0;memset(dfn, 0, sizeof dfn);memset(low, 0, sizeof low);memset(vis, 0, sizeof vis);memset(subnet, 0, sizeof subnet);}void dfs(int u, int k){low[u] = dfn[u] = tmpdfn++;vis[u] = 1;for (int i = s[u]; ~i; i = nt[i]){int v = e[i];if (vis[v] == 2) continue;if (!vis[v]){dfs(v, k);low[u] = min(low[u], low[v]);if (low[v] >= dfn[u]){if (u != k) subnet[u]++;else son++;}}else low[u] = min(low[u], dfn[v]);}}int main(){while (~scanf("%d%d", &n, &m) && (n + m)){memset(s, -1, sizeof s);int u, v, cnt = 1;for (int i = 1; i <= m; i++){scanf("%d%d", &u, &v);nt[cnt] = s[u], s[u] = cnt, e[cnt++] = v;nt[cnt] = s[v], s[v] = cnt, e[cnt++] = u;}int flag = 0;for (int i = 0; i < n; i++){init();vis[i] = 2;dfs((i + 1) % n, (i + 1) % n);subnet[i] = son - 1;for (int j = 0; j < n; j++)if (subnet[j]) flag = 1;if (flag) break;}if (flag) printf("NO\n");else printf("YES\n");}return 0;}

原创粉丝点击