Smallest Minimum Cut

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2281    Accepted Submission(s): 913

Problem Description
Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition of nodes set V into two parts such that s and t belong to different parts. The cut set is the subset of E with all edges connecting nodes in different parts. A minimum cut is the one whose cut set has the minimum summation of capacities. The size of a cut is the number of edges in the cut set. Please calculate the smallest size of all minimum cuts.
 
Input
The input contains several test cases and the first line is the total number of cases T (1≤T≤300).
Each case describes a network G, and the first line contains two integers n (2≤n≤200) and m (0≤m≤1000) indicating the sizes of nodes and edges. All nodes in the network are labelled from 1 to n.
The second line contains two different integers s and t (1≤s,t≤n) corresponding to the source and sink.
Each of the next m lines contains three integers u,v and w (1≤w≤255) describing a directed edge from node u to v with capacity w.
 
Output
For each test case, output the smallest size of all minimum cuts in a line.
 
Sample Input
2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 3
 
Sample Output
2
3
 
就是求最小割的边的集合
 
最小割的边就等于满流的边
1、将每条边的权值改为w*(m+1)+1, 最后求的最大流除以(m+1)就是原图的最大流,模上(m+1)就是最小割的边
2、求得最大流之后,将所有的满流的边权设为1,不满流的边权设为INF,然后跑一边最大流就是最小割的边
 
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <sstream>
  4. #include <cstring>
  5. #include <map>
  6. #include <cctype>
  7. #include <set>
  8. #include <vector>
  9. #include <stack>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <cmath>
  13. #define rap(i, a, n) for(int i=a; i<=n; i++)
  14. #define rep(i, a, n) for(int i=a; i<n; i++)
  15. #define lap(i, a, n) for(int i=n; i>=a; i--)
  16. #define lep(i, a, n) for(int i=n; i>a; i--)
  17. #define rd(a) scanf("%d", &a)
  18. #define rlld(a) scanf("%lld", &a)
  19. #define rc(a) scanf("%c", &a)
  20. #define rs(a) scanf("%s", a)
  21. #define MOD 2018
  22. #define LL long long
  23. #define ULL unsigned long long
  24. #define Pair pair<int, int>
  25. #define mem(a, b) memset(a, b, sizeof(a))
  26. #define _ ios_base::sync_with_stdio(0),cin.tie(0)
  27. //freopen("1.txt", "r", stdin);
  28. using namespace std;
  29. const int maxn = , INF = 0x7fffffff;
  30. int head[maxn], cnt;
  31. int d[maxn], vis[maxn], cur[maxn];
  32. int s, t;
  33. struct node
  34. {
  35. int u, v, c, next;
  36. }Node[maxn<<];
  37.  
  38. void add_(int u, int v, int c)
  39. {
  40. Node[cnt].u = u;
  41. Node[cnt].v = v;
  42. Node[cnt].c = c;
  43. Node[cnt].next = head[u];
  44. head[u] = cnt++;
  45. }
  46.  
  47. void add(int u, int v, int c)
  48. {
  49. add_(u, v, c);
  50. add_(v, u, );
  51. }
  52.  
  53. void init()
  54. {
  55. mem(head, -);
  56. cnt = ;
  57. }
  58.  
  59. bool bfs()
  60. {
  61. queue<int> Q;
  62. mem(d, );
  63. Q.push(s);
  64. d[s] = ;
  65. while(!Q.empty())
  66. {
  67. int u = Q.front(); Q.pop();
  68. for(int i=head[u]; i!=-; i=Node[i].next)
  69. {
  70. node e = Node[i];
  71. if(!d[e.v] && e.c > )
  72. {
  73. d[e.v] = d[e.u] + ;
  74. Q.push(e.v);
  75. if(e.v == t) return ;
  76. }
  77. }
  78. }
  79. return d[t] != ;
  80. }
  81.  
  82. int dfs(int u, int cap)
  83. {
  84. int ret = , V;
  85. if(u==t || cap == )
  86. return cap;
  87. for(int &i=cur[u]; i!=-; i=Node[i].next)
  88. {
  89. node e = Node[i];
  90. if(d[e.v] == d[e.u] + && e.c > )
  91. {
  92. int V = dfs(e.v, min(cap, e.c));
  93. Node[i].c -= V;
  94. Node[i^].c += V;
  95. ret += V;
  96. cap -= V;
  97. if(cap == ) break;
  98. }
  99. }
  100. if(cap > ) d[u] = -;
  101. return ret;
  102. }
  103.  
  104. int dinic(int u)
  105. {
  106. int ans = ;
  107. while(bfs())
  108. {
  109. memcpy(cur, head, sizeof(head));
  110. ans += dfs(u, INF);
  111. }
  112. return ans;
  113. }
  114.  
  115. int main()
  116. {
  117. int T, n, m;
  118. rd(T);
  119. while(T--)
  120. {
  121. int u, v, c;
  122. init();
  123. rd(n); rd(m);
  124. rd(s), rd(t);
  125. rep(i, , m)
  126. {
  127. rd(u), rd(v), rd(c);
  128. add(u, v, c*(m+) + );
  129. }
  130.  
  131. int res = dinic(s);
  132. cout<< res % (m+) <<endl;
  133.  
  134. }
  135.  
  136. return ;
  137. }

Smallest Minimum Cut HDU - 6214(最小割集)的更多相关文章

  1. HDU 6214 Smallest Minimum Cut(最少边最小割)

    Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition o ...

  2. HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】

    Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...

  3. HDU 6214.Smallest Minimum Cut 最少边数最小割

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  4. hdu 6214 Smallest Minimum Cut[最大流]

    hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...

  5. HDU - 6214:Smallest Minimum Cut(最小割边最小割)

    Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes ...

  6. HDU-6214 Smallest Minimum Cut(最少边最小割)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 Problem Description Consider a network G=(V,E) w ...

  7. HDU 6214 最小割边

    双倍经验题:HDU 6214,3987 求最小割的最小边. 方案一: 首先跑最大流,这个时候割上都满载了,于是将满载的边 cap = 1,其他 inf ,再跑最大流,这个时候限定这个网络的关键边就是那 ...

  8. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  9. HDU 6214 Smallest Minimum Cut (最小割且边数最少)

    题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...

随机推荐

  1. Linu之linux系统基础优化和基本命令

    Linux系统基础优化和基本命令 网络参数设定命令 ifconfig: 查询,设置网卡和ip等参数 ifup,ifdown: 脚本命令,更简单的方式 ip: 符合指令,直接修改上述功能 编辑网卡配置文 ...

  2. 树莓派UPS-18650,添加时钟

    1.简介 UPS-18650 是一个专门为树莓派(以下简称 pi)所设计的 UPS 电源,采用两颗标准 的 18650 锂电池进行供电,支持外部电源插入检测,支持边充边放,既插上外部电源时, pi 由 ...

  3. Scrapy爬取携程桂林问答

    guilin.sql: CREATE TABLE `guilin_ask` ( `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键', `question ...

  4. VMware Workstation and Device/Credential Guard are not compatible

    VMware Workstation and Device/Credential Guard are not compatible. VMware Workstation can be run aft ...

  5. MySQL两种引擎的比较

    MyISAM,InnoDB主要区别: 1.MyISAM是非事物安全的,InnoDB是事物安全的. 事物安全的特点为更安全,遇到问题会自动恢复或从备份加事物日志回复,如果更新失败,你的所有改变都变回原来 ...

  6. CHAPTER 24 History of Our Planet 第24章 我们行星的历史

    CHAPTER 24 History of Our Planet 第24章 我们行星的历史 Uncovering the bones of ancient beasts is only part of ...

  7. Tree - Decision Tree with sklearn source code

    After talking about Information theory, now let's come to one of its application - Decision Tree! No ...

  8. 20162328蔡文琛 week11 大二

    20162328 2017-2018-1 <程序设计与数据结构>第十一周学习总结 教材学习内容总结 在无向图中,表示边的顶点对是无序的. 如果图中的两个顶点之间有边链接,则称它们是领接的. ...

  9. java List.get

    并不能 用如果List在i位置值不存在 并不能 List.get(i) !=null 判断 会抛异常 版权声明:本文为博主原创文章,未经博主允许不得转载.

  10. iis托管管道模式-学习

    文章;IIS 7 托管管道模式 经典模式(Classic) 集成模式(Integrated) 分析与理解 我们可以通过应用程序池设置管道模式,这项功能对IIS管理员尤其有用,因为这样既可以令一台服务器 ...