Cable TV NETWORK
The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there is at least one interconnection path between each pair of relays present in the network. Otherwise the network is disconnected. An empty network or a network with a single relay is considered connected. The safety factor f of a network with n relays is: 
1. n, if the net remains connected regardless the number of relays removed from the net. 
2. The minimal number of relays that disconnect the network when removed. 

For example, consider the nets from figure 1, where the circles mark the relays and the solid lines correspond to interconnection cables. The network (a) is connected regardless the number of relays that are removed and, according to rule (1), f=n=3. The network (b) is disconnected when 0 relays are removed, hence f=0 by rule (2). The network (c) is disconnected when the relays 1 and 2 or 1 and 3 are removed. The safety factor is 2.

Input

Write a program that reads several data sets from the standard input and computes the safety factor for the cable networks encoded by the data sets. Each data set starts with two integers: 0<=n<=50,the number of relays in the net, and m, the number of cables in the net. Follow m data pairs (u,v), u < v, where u and v are relay identifiers (integers in the range 0..n-1). The pair (u,v) designates the cable that interconnects the relays u and v. The pairs may occur in any order.Except the (u,v) pairs, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct.

Output

For each data set, the program prints on the standard output, from the beginning of a line, the safety factor of the encoded net.

Sample Input

0 0
1 0
3 3 (0,1) (0,2) (1,2)
2 0
5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)

Sample Output

0
1
3
0
2

Hint

The first data set encodes an empty network, the second data set corresponds to a network with a single relay, and the following three data sets encode the nets shown in figure 1.
题意:给你N个点,以及M个关系,让你求最少去掉多少个点才能使得其中两个点补连通;
题解:最小点割集; 没个点只能去掉一次,因此我们可将每一个点拆分为两个点中间用一条边权为1的边连接(表示只能经过一次,也就是改点只能去掉一次),然后对于其他相连得
两个点U,V: 我们将它们分别分成两个点后U1,U2,V1,V2,建立U1,V2,和V1,U2且其权值为INF(表示可以走无数次),然后根据题意,任意两点无法连通即可;这就转化为
求最小割的问题,最小割==最大流;即求任意不同且不相邻的两点间的最大流,然后取最小的即可;
参考代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-8
#define mem(a,b) memset(a,b,sizeof a)
typedef long long LL;
typedef pair<int,int> P;
const int INF=0x3f3f3f3f;
const int maxn=;
int n,m,s,t,u,v,tot;
struct Edge{
int from,to,cap,flow;
Edge(int _f,int _t,int _c,int _fl):from(_f),to(_t),cap(_c),flow(_fl) {}
};
vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn],cur[maxn],flag[][]; void Init()
{
mem(d,); tot=;
for(int i=;i<=*n+;i++) G[i].clear();
} void Addedge(int from,int to,int cap)
{
edges.push_back(Edge(from,to,cap,));
edges.push_back(Edge(to,from,,));
int m=edges.size();
G[from].push_back(m-); G[to].push_back(m-);
} bool bfs()
{
memset(vis,,sizeof vis);
queue<int> q;
q.push(s);
d[s] = ; vis[s] = ;
while (!q.empty())
{
int x = q.front(); q.pop();
for(int i = ; i < G[x].size(); ++i)
{
Edge &e = edges[G[x][i]];
if (!vis[e.to] && e.cap > e.flow)
{
vis[e.to] = ;
d[e.to] = d[x] + ;
q.push(e.to);
}
}
}
return vis[t];
} int dfs(int x,int a)
{
if(x == t || a == ) return a;
int flow = , f;
for(int &i = cur[x]; i < G[x].size(); ++i)
{
Edge &e = edges[G[x][i]];
if (d[e.to] == d[x] + && (f=dfs(e.to, min(a, e.cap-e.flow))) > )
{
e.flow += f;
edges[G[x][i]^].flow -= f;
flow += f; a -= f;
if (a == ) break;
}
}
return flow;
} int Maxflow(int s, int t)
{
int flow = ;
while (bfs())
{
memset(cur,,sizeof cur);
flow += dfs(s, INF);
}
return flow;
} struct Node{
int u,v;
} edg[maxn]; int build(int u,int v)
{
Init();
s=u+n; t=v;
for(int i=;i<=n;++i) Addedge(i,i+n,);
for(int i=;i<m;i++)
{
Addedge(edg[i].u+n,edg[i].v,INF);
Addedge(edg[i].v+n,edg[i].u,INF);
}
return Maxflow(s,t);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(!m)
{
if(n==) puts("");
else puts("");
continue;
}
mem(flag,);
for(int i=;i<m;++i)
{
scanf(" (%d,%d)", &edg[i].u, &edg[i].v);
edg[i].u++; edg[i].v++;
flag[edg[i].u][edg[i].v]=flag[edg[i].v][edg[i].u]=;
}
int ans=INF;
for(int i=;i<n;++i)
for(int j=i+;j<=n;++j)
if(!flag[i][j]) ans=min(ans,build(i,j));
ans=min(ans,n);
printf("%d\n",ans);
}
return ;
}

  

POJ 1966 Cable TV NETWORK(网络流-最小点割集)的更多相关文章

  1. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  2. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

  3. POJ 1966 Cable TV Network (无向图点连通度)

    [题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...

  4. POJ 1966:Cable TV Network(最小点割集)***

    http://poj.org/problem?id=1966 题意:给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. 思路:将点i拆成a和b,连一条a-&g ...

  5. POJ 1966 Cable TV Network (点连通度)【最小割】

    <题目链接> 题目大意: 给定一个无向图,求点连通度,即最少去掉多少个点使得图不连通. 解题分析: 解决点连通度和边连通度的一类方法总结见   >>> 本题是求点连通度, ...

  6. POJ 1966 Cable TV Network 【经典最小割问题】

    Description n个点的无向图,问最少删掉几个点,使得图不连通 n<=50 m也许可以到完全图? Solution 最少,割点,不连通,可以想到最小割. 发现,图不连通,必然存在两个点不 ...

  7. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...

  8. POJ 1966 Cable TV Network (最大流最小割)

    $ POJ~1966~Cable~TV~Network $ $ solution: $ 第一眼可能让人很难下手,但本就是冲着网络流来的,所以我们直接一点.这道题我们要让这个联通图断开,那么势必会有两个 ...

  9. POJ 1966 Cable TV Network (算竞进阶习题)

    拆点+网络流 拆点建图应该是很常见的套路了..一张无向图不联通,那么肯定有两个点不联通,但是我们不知道这两个点是什么. 所以我们枚举所有点,并把每个点拆成入点和出点,每次把枚举的两个点的入点作为s和t ...

随机推荐

  1. 【集合系列】- 深入浅出分析LinkedHashMap

    一.摘要 在集合系列的第一章,咱们了解到,Map的实现类有HashMap.LinkedHashMap.TreeMap.IdentityHashMap.WeakHashMap.Hashtable.Pro ...

  2. (二十一)golang--字符串中的函数

    golang中ascii对应的字符占一个字节,而汉字占三个字节. (1)统计字符串的长度len (2)字符串遍历,同时处理有中文的问题r:=[]rune(str) (3)字符串转整数:n,err:= ...

  3. nyoj 38-布线问题(prim, sort)

    38-布线问题 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:5 submit:11 题目描述: 南阳理工学院要进行用电线路改造,现在校长要求设计师 ...

  4. nyoj 100-1的个数 (因为只统计1的个数,连栈都不需要了)

    100-1的个数 内存限制:64MB 时间限制:3000ms 特判: No 通过数:33 提交数:42 难度:1 题目描述: 小南刚学了二进制,他想知道一个数的二进制表示中有多少个1,你能帮他写一个程 ...

  5. node.js和ionic

    1.安装node.js node -v  检测node文件是否安装成功 node --version  检查node版本号 2.Npm   node package manager 管理工具  管理模 ...

  6. 领扣(LeetCode)两数之和II - 输入有序数组 个人题解

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值 ...

  7. windows 10安装和配置caffe教程 | Install and Configure Caffe on windows 10

    本文首发于个人博客https://kezunlin.me/post/1739694c/,欢迎阅读! Install and Configure Caffe on windows 10 Part 1: ...

  8. PL真有意思(五):数据类型

    前言 现在大多数程序设计语言中都有表达式和/或对象的类型概念.类型起着两种主要作用: 为许多操作提供了隐含的上下文信息,使程序员可以在许多情况下不必显示的描述这种上下文.比如int类型的两个对象相加就 ...

  9. 研究Java语言的编译器和虚拟机源代码

    现在使用Java语言的人很多,但是了解Java语言实现的人非常少.如果要研究Java语言的实现,推荐研究Javac和虚拟机HotSpot的源代码实现,其中Javac相当于Java编译的前端,HotSp ...

  10. Learning Markov Clustering Networks for Scene Text Detection

    Learning Markov Clustering Networks for Scene Text Detection 论文下载:https://arxiv.org/pdf/1805.08365v1 ...