原题链接

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

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

枚举每两个不能直接到达的点\(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. pycahrm 激活

    Linux在/etc/hosts中添加 0.0.0.0 account.jetbrains.com就好,直接添加:0.0.0.0 account.jetbrains.comwindows的话没记错应该 ...

  2. anchor_generator.proto:11:3: Expected "required", "optio nal", or "repeated"

    转自:https://github.com/tensorflow/models/issues/1834 When I use the commond " protoc object_dete ...

  3. 网络传输中利用fastjson将复杂嵌套数据类型Json格式转换(GeoJsonPolygon)

    如果一个对象太复杂了,那么在网络传输键的JSON格式数据转换容易出问题. 比如下面一个类Area.java import lombok.AllArgsConstructor; import lombo ...

  4. php分割最后一个逗号后面的字符

    $str = 'a/b/c/d/e/f'; echo preg_replace('/.*\//','',$str);     echo preg_replace('/.*,/','',$str);最后 ...

  5. 【翻译】View Frustum Culling --2 Geometric Approach – Extracting the Planes

    在上一篇中,我们知道了视锥体的形状,并且也确定了我们进行裁剪时的步骤.那我们接下来要走的就是确定视锥体的六个平面: near, far, top, bottom, left and right 2.计 ...

  6. 算法之LOWB三人组之冒泡排序

    排序 冒泡排序(Bubble Sort)时间复杂度为O(n^2) 列表每两个相邻的数,如果前面比后面大,则交换这两个数 一趟排序完成后,则无序区减少一个数,有序区增加一个数. def bubble_s ...

  7. 665. Non-decreasing Array

    Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...

  8. IronPython 的几个问题

    1.在脚本中使用datagridview.Rows[i].Cells[1].Value并将其转换为string时,遇到int类型 有时可是直接使用.toString()转换为字符 有时必须采用str( ...

  9. hdoj1005(循环,找规律)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  10. 修改django后台用户名和密码

    cd到manage.py目录下 python manage.py shell >>from django.contrib.auth.models import User >>u ...