题目地址:UVA1660 电视网络 Cable TV Network

枚举两个不直接连通的点 \(S\) 和 \(T\) ,求在剩余的 \(n-2\) 个节点中最少去掉多少个可以使 \(S\) 和 \(T\) 不连通,在每次枚举的结构中取 \(min\) 就是本题的答案。

点边转化

把原来无向图中的每个点 \(x\) ,拆成入点 \(x\) 和出点 \(x'\) 。在无向图中删去一个点⇔在网络中断开 \((x,x')\) 。对 \(\forall x \neq S,x \neq T\) 连有向边 \((x,x')\) ,容量为 \(1\) 。对原无向图的每条边 \((x,y)\) ,连有向边 \((x',y),(y',x)\) ,容量为 \(+ \infty\) (防止割断)。

求最小割即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 56, M = 2e4 + 6, inf = 0x3f3f3f3f;
  4. int n, m, s, t;
  5. int a[N*N], b[N*N], d[N<<1];
  6. int Head[N<<1], Edge[M], Leng[M], Next[M], tot;
  7. inline void add(int x, int y, int z) {
  8. Edge[++tot] = y;
  9. Leng[tot] = z;
  10. Next[tot] = Head[x];
  11. Head[x] = tot;
  12. Edge[++tot] = x;
  13. Leng[tot] = 0;
  14. Next[tot] = Head[y];
  15. Head[y] = tot;
  16. }
  17. inline bool bfs() {
  18. memset(d, 0, sizeof(d));
  19. queue<int> q;
  20. q.push(s);
  21. d[s] = 1;
  22. while (q.size()) {
  23. int x = q.front();
  24. q.pop();
  25. for (int i = Head[x]; i; i = Next[i]) {
  26. int y = Edge[i], z = Leng[i];
  27. if (z && !d[y]) {
  28. q.push(y);
  29. d[y] = d[x] + 1;
  30. if (y == t) return 1;
  31. }
  32. }
  33. }
  34. return 0;
  35. }
  36. inline int dinic(int x, int f) {
  37. if (x == t) return f;
  38. int rest = f;
  39. for (int i = Head[x]; i && rest; i = Next[i]) {
  40. int y = Edge[i], z = Leng[i];
  41. if (z && d[y] == d[x] + 1) {
  42. int k = dinic(y, min(rest, z));
  43. if (!k) d[y] = 0;
  44. Leng[i] -= k;
  45. Leng[i^1] += k;
  46. rest -= k;
  47. }
  48. }
  49. return f - rest;
  50. }
  51. inline void Cable_TV_Network() {
  52. for (int i = 0; i < m; i++) {
  53. char str[20];
  54. scanf("%s", str);
  55. a[i] = b[i] = 0;
  56. int j;
  57. for (j = 1; str[j] != ','; j++) a[i] = a[i] * 10 + str[j] - '0';
  58. for (j++; str[j] != ')'; j++) b[i] = b[i] * 10 + str[j] - '0';
  59. }
  60. int ans = inf;
  61. for (s = 0; s < n; s++)
  62. for (t = 0; t < n; t++)
  63. if (s != t) {
  64. memset(Head, 0, sizeof(Head));
  65. tot = 1;
  66. int maxf = 0;
  67. for (int i = 0; i < n; i++)
  68. if (i == s || i == t) add(i, i + n, inf);
  69. else add(i, i + n, 1);
  70. for (int i = 0; i < m; i++) {
  71. add(a[i] + n, b[i], inf);
  72. add(b[i] + n, a[i], inf);
  73. }
  74. while (bfs()) {
  75. int num;
  76. while ((num = dinic(s, inf))) maxf += num;
  77. }
  78. ans = min(ans, maxf);
  79. }
  80. if (n <= 1 || ans == inf) ans = n;
  81. cout << ans << endl;
  82. }
  83. int main() {
  84. while (cin >> n >> m) Cable_TV_Network();
  85. return 0;
  86. }

UVA1660 电视网络 Cable TV Network的更多相关文章

  1. UVA1660 电视网络 Cable TV Network[拆点+最小割]

    题意翻译 题目大意: 给定一个n(n <= 50)个点的无向图,求它的点联通度.即最少删除多少个点,使得图不连通. 解析 网络瘤拆点最小割. 定理 最大流\(=\)最小割 感性地理解(口胡)一下 ...

  2. 【UVA1660】Cable TV Network

    题目大意:给定一个 N 个点的无向图,求至少删去多少个点可以使得无向图不连通. 题解:学习到了点边转化思想. 根据网络流的知识可知,一个网络的最小割与网络的最大流相等.不过最小割是图的边集,而本题则是 ...

  3. POJ 1966 Cable TV Network

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

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

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

  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. UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)

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

  8. UVA-1660 Cable TV Network (最小割)

    题目大意:给一张n个点.m条边的无向图,求最小点割集的基数. 题目分析:求无向图最小点割集的基数可以变成求最小割.考虑单源s单汇t的无向图,如果要求一个最小点集,使得去掉这个点集后图不再连通(连通分量 ...

  9. UVA1660 Cable TV Network (无向图的点连通度)

    题意:求一个无向图的点连通度. 把一个点拆成一个入点和一个出点,之间连一条容量为1的有向边,表示能被用一次.最大流求最小割即可. 一些细节的东西:1.源点固定,汇点要枚举一遍,因为最小割割断以后会形成 ...

随机推荐

  1. Go多组Raft库

    Go多组Raft库 https://github.com/lni/dragonboat/blob/master/README.CHS.md 使用用例 https://github.com/lni/dr ...

  2. Ansible Callback

    非api模式下自定义callback ansible.cfg中开启callback功能 callback_plugins = /usr/share/ansible/plugins/callback # ...

  3. Spring Boot笔记三:配置文件

    配置文件这里需要讲的东西很多,所以我写在了这里,但是这个是和上篇文章衔接的,所以看这篇文章,先看上篇文章笔记二 一.单独的配置文件 配置文件里面不能都写我们的类的配置吧,这样那么多类太杂了,所以我们写 ...

  4. Ubuntu 开启SSH服务以及有关设置:安装,指定端口号、免密登录、远程拷贝

    本文所用系统为 Ubuntu 18.04   什么是SSH?     简单说,SSH是一种网络协议,用于计算机之间的加密登录.全名为:安全外壳协议.为Secure Shell的缩写.SSH为建立在应用 ...

  5. 020、搭建本地Registry(2019-01-11 周五)

    参考https://www.cnblogs.com/CloudMan6/p/6902325.html   Docker Hub 虽然方便,但还是有些限制,比如     1.需要Internet连接,上 ...

  6. 使用模拟Table解决span重叠问题

    <div id="test"> <div > <span>adfafadsfadfa</span> <span style=& ...

  7. exec存储过程示例

    假如存储过程为test,两个参数为aa,bb那么有以下两种写法,不要带括号EXEC [dbo].[test] @aa = 111, @bb = 222 exec test 111,222

  8. C++使用libcurl

    1.下载地址https://curl.haxx.se/download.html 2.选择zip压缩包下载 3.选择合适自己的vc版本 4.启动项目选择libcurl 5.因为暂时不需要ssh2,预处 ...

  9. spring注解第01课 @Configuration、@Bean

    一.原始的 xml配置方式 1.Spring pom 依赖 <dependency> <groupId>org.springframework</groupId> ...

  10. 20155324 2016-2017-2 《Java程序设计》第5周学习总结

    20155324 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 try.catch 1.求平均数程序示例 import java.util.Scanner; ...