原题链接

割去点使得无向图不连通,和最小割相似。

我们可以将点转化成边,这样就能跑最小割了。

枚举每两个不能直接到达的点\(S,T\),使得删去一些点(除去这两个点)使得这两个点不连通(若两点能直接到达显然无解),然后我们按下面的方法建立新图:

  1. 将每个点\(x\),拆成两个点\(x_1,x_2\),对\(\forall x\ne S,x\ne T\),由\(x_1\)向\(x_2\)连一条容量为\(1\)的边。
  2. 对于原来图中每条边\((x,y)\),连接\((x_2,y_1)\)和\((y_2,x_1)\),容量为\(+\infty\)。

然后以\(S_2\)为源点,\(T_1\)为汇点,求最小割即可。

注意\(n\leqslant 1\)或最终求出的最小割为\(+\infty\)时,答案为\(n\)。

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1010;
const int M = 1e4 + 10;
struct eg {
int x, y;
};
eg b[M];
int fi[N], ne[M], di[M], da[M], cu[N], de[N], q[M << 4], l, st, ed, n, m;
bool a[52][52];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c <'0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void add(int x, int y, int z)
{
di[++l] = y;
da[l] = z;
ne[l] = fi[x];
fi[x] = l;
di[++l] = x;
da[l] = 0;
ne[l] = fi[y];
fi[y] = l;
}
inline int minn(int x, int y)
{
return x < y ? x : y;
}
bool bfs()
{
int head = 0, tail = 1, i, x, y;
memset(de, 0, sizeof(de));
de[st] = 1;
q[1] = st;
while (head ^ tail)
{
x = q[++head];
for (i = fi[x]; i; i = ne[i])
if (!de[y = di[i]] && da[i] > 0)
{
de[y] = de[x] + 1;
if (!(y ^ ed))
return true;
q[++tail] = y;
}
}
return false;
}
int dfs(int x, int k)
{
int y, mi;
if (!(x ^ ed))
return k;
for (int &i = cu[x]; i; i = ne[i])
if (!(de[y = di[i]] ^ (de[x] + 1)) && da[i] > 0)
{
mi = dfs(y, minn(k, da[i]));
if (mi > 0)
{
da[i] -= mi;
da[i ^ 1] += mi;
return mi;
}
}
return 0;
}
void bumap()
{
int i;
memset(fi, 0, sizeof(fi));
l = 1;
for (i = 1; i <= n; i++)
if (i ^ (st - n) && i ^ ed)
add(i, i + n, 1);
for (i = 1; i <= m; i++)
{
add(b[i].x + n, b[i].y, 1e9);
add(b[i].y + n, b[i].x, 1e9);
}
}
int main()
{
int i, j, x, y, s, mi, k, o;
while (scanf("%d%d", &n, &m) == 2)
{
o = n << 1;
mi = 1e9;
memset(a, 0, sizeof(a));
for (i = 1; i <= m; i++)
{
x = re() + 1;
y = re() + 1;
a[x][y] = a[y][x] = 1;
b[i].x = x;
b[i].y = y;
}
for (i = 1; i < n; i++)
for (j = i + 1; j <= n; j++)
if (!a[i][j])
{
st = i + n;
ed = j;
bumap();
s = 0;
while (bfs())
{
for (k = 1; k <= o; k++)
cu[k] = fi[k];
while ((x = dfs(st, 1e9)) > 0)
s += x;
}
mi = minn(mi, s);
}
printf("%d\n", mi == 1e9 || n <= 1 ? n : mi);
}
return 0;
}

POJ1966 Cable TV Network的更多相关文章

  1. 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)

    题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...

  2. POJ 1966 Cable TV Network

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

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

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

  4. UVA1660 电视网络 Cable TV Network

    题目地址:UVA1660 电视网络 Cable TV Network 枚举两个不直接连通的点 \(S\) 和 \(T\) ,求在剩余的 \(n-2\) 个节点中最少去掉多少个可以使 \(S\) 和 \ ...

  5. POJ 1966 Cable TV NETWORK(网络流-最小点割集)

                                    Cable TV NETWORK The interconnection of the relays in a cable TV net ...

  6. Cable TV Network 顶点连通度 (最大流算法)

    Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度   K 算法:将每个顶点v拆成 v'   v''  ,v'-->v''的容量为1.       ...

  7. ZOJ 2182 Cable TV Network(无向图点割-最大流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182 题意:给出一个无向图,问最少删掉多少个顶点之后图变得不连通 ...

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

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

  9. UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)

    题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...

随机推荐

  1. trie数的实现

    Trie树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串 ...

  2. python使用cv2显示图片像素值

    给定一张灰度图,显示这张图片的像素值 def show_image_pixel(img): ''' :param img: 需要输出像素值的图像,要求是灰度图 :return: 无返回值 ''' he ...

  3. 文件上传以及JS链式结构

    文件上传: 文件上传使用FileUpload控件,使用控件的SaveAs方法,需要绝对路径. 获取文件的绝对路径:Server.MapPath(相对路径); 或许要上传文件的本身名字用.FileNam ...

  4. mysql 拼接字符

    Mysql的查询结果行字段拼接,可以用下面两个函数实现: 1. concat函数 mysql> select concat('1','2','3') from test ; +--------- ...

  5. scrapy 是指user_agent

    1.倒入random模块 2.在settings文件中添加useragent列表 MY_USER_AGENT = [ "Mozilla/4.0 (compatible; MSIE 6.0; ...

  6. 根据23423条件,截取字段‘abdecsdsadsadsad’,以ab/dec/sdsa/ds/ads 输出

    create or replace procedure p_getString ( p_finalString out varchar2, p_rulestring in number, p_sour ...

  7. exe4j 安装

    需要看清楚对应的jre版本 4.6---jre1.6 5.0以上---jre1.7

  8. Java读取文件时第一行出现乱码“?”问号

    我们在使用Java在读取文件(txt.dat等)时,如果文件不是utf-8格式的话,读取结果会出现,中文字符变乱码的情况,所以一般在读取时转为UTF-8格式读取. 但这时会出现一种情况,第一次读取第一 ...

  9. style标签下的CSS代码的显示与实时编辑

    style标签也是标签 首先设置body style的样式 body style{ display:block; padding:0.6em 0.8em; border:1px dashed #ccc ...

  10. html position定位

    一.fixed居中 css样式代码:{ position:fixed left: 0; right: 0; margin:0 auto; width:300px } 二.Position属性有四个值: ...