POJ 1966 Cable TV NETWORK(网络流-最小点割集)
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
Output
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
#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(网络流-最小点割集)的更多相关文章
- POJ 1966 Cable TV Network
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4702 Accepted: 2173 ...
- POJ 1966 Cable TV Network(顶点连通度的求解)
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- POJ 1966 Cable TV Network (无向图点连通度)
[题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...
- POJ 1966:Cable TV Network(最小点割集)***
http://poj.org/problem?id=1966 题意:给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. 思路:将点i拆成a和b,连一条a-&g ...
- POJ 1966 Cable TV Network (点连通度)【最小割】
<题目链接> 题目大意: 给定一个无向图,求点连通度,即最少去掉多少个点使得图不连通. 解题分析: 解决点连通度和边连通度的一类方法总结见 >>> 本题是求点连通度, ...
- POJ 1966 Cable TV Network 【经典最小割问题】
Description n个点的无向图,问最少删掉几个点,使得图不连通 n<=50 m也许可以到完全图? Solution 最少,割点,不连通,可以想到最小割. 发现,图不连通,必然存在两个点不 ...
- poj 1966 Cable TV Network 顶点连通度
题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...
- POJ 1966 Cable TV Network (最大流最小割)
$ POJ~1966~Cable~TV~Network $ $ solution: $ 第一眼可能让人很难下手,但本就是冲着网络流来的,所以我们直接一点.这道题我们要让这个联通图断开,那么势必会有两个 ...
- POJ 1966 Cable TV Network (算竞进阶习题)
拆点+网络流 拆点建图应该是很常见的套路了..一张无向图不联通,那么肯定有两个点不联通,但是我们不知道这两个点是什么. 所以我们枚举所有点,并把每个点拆成入点和出点,每次把枚举的两个点的入点作为s和t ...
随机推荐
- 【html css js】实现一个简易日历
——[效果预览] 实现了日历最基础的功能,当前日期红色显示,可通过上方的左右按钮查看上一月或下一月的日期. ——[代码部分] 1. HTML <body> <div class=&q ...
- mysql导入sql出错,无脑解决办法
找到my.cnf文件在[mysqld]的下面添加 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTI ...
- js在字符串中加入一段字符串
在这个功能的实现主要是slice()方法的掌握 arrayObject.slice(start,end) start 必需.规定从何处开始选取.如果是负数,那么它规定从数组尾部开始算起的位置.也就是说 ...
- ThinkPHP v5.1.x POP 链分析
环境:MacOS 10.13 MAMAP Prophp 7.0.33 + xdebugVisual Studio Code前言我所理解的 POP Chain:利用魔术方法并巧妙构造特殊属性调用一系列函 ...
- PHP 修改数组中的值
PHP 修改数组中的值 ①.二维数组可以通过 for($i = 0; $i < count(Array()); ++ $i) 这种形式修改 实例代码: // 修改 二维数组中的 name为 Ge ...
- 06_K-近邻算法
k-近邻算法 算法介绍 定义: 如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一类别,则该样本也属于这个类别. 计算距离公式:欧式距离 (两点之间距离) 需要做标准化 ...
- 工作日志,error parsing query: unable to find time zone
工作日志,error parsing query: unable to find time zone 坑 Windows 系统使用influxdb数据库,在执行查询语句时提示 ERR: error p ...
- Stack Overflow 上 370万浏览量的一个问题:如何比较 Java 的字符串?
在逛 Stack Overflow 的时候,发现了一些访问量像喜马拉雅山一样高的问题,比如说这个:如何比较 Java 的字符串?访问量足足有 370万+,这不得了啊!说明有很多很多的程序员被这个问题困 ...
- 复制节点(cloneNode)
DOM提供用来复制节点方法. cloneNode():将为给定节点创建一个副本,这个方法的返回值是一个指向新建克隆节点的引用指针, reference = node.cloneNode(deep) 这 ...
- Hibernate注解之@Enumerated:针对枚举enum(转)
https://my.oschina.net/xinxingegeya/blog/359968 @Column(name = "store_type", nullable = fa ...