Minimum Cut
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 9302   Accepted: 3902
Case Time Limit: 5000MS

Description

Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must be removed at least to disconnect the graph into two subgraphs?

Input

Input contains multiple test cases. Each test case starts with two integers N and M (2 ≤ N ≤ 500, 0 ≤ M ≤ N × (N − 1) ⁄ 2) in one line, where N is the number of vertices. Following are M lines, each line contains Mintegers AB and C (0 ≤ AB < NA ≠ BC > 0), meaning that there C edges connecting vertices A and B.

Output

There is only one line for each test case, which contains the size of the minimum cut of the graph. If the graph is disconnected, print 0.

Sample Input

  1. 3 3
  2. 0 1 1
  3. 1 2 1
  4. 2 0 1
  5. 4 3
  6. 0 1 1
  7. 1 2 1
  8. 2 3 1
  9. 8 14
  10. 0 1 1
  11. 0 2 1
  12. 0 3 1
  13. 1 2 1
  14. 1 3 1
  15. 2 3 1
  16. 4 5 1
  17. 4 6 1
  18. 4 7 1
  19. 5 6 1
  20. 5 7 1
  21. 6 7 1
  22. 4 0 1
  23. 7 3 1

Sample Output

  1. 2
  2. 1
  3. 2

Source

Baidu Star 2006 Semifinal 
Wang, Ying (Originator) 
Chen, Shixi (Test cases)

[Submit]   [Go Back]   [Status]   [Discuss]

无向图的边连通度,有一个神奇的算法,还有我蒟蒻的模板。

  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. inline int min(int a, int b)
  5. {
  6. return a < b ? a : b;
  7. }
  8.  
  9. const int inf = 2e9;
  10. const int maxn = ;
  11.  
  12. int n, m;
  13. int vis[maxn];
  14. int wet[maxn];
  15. int com[maxn];
  16. int G[maxn][maxn];
  17.  
  18. inline int search(int &S, int &T)
  19. {
  20. memset(vis, , sizeof(vis));
  21. memset(wet, , sizeof(wet));
  22.  
  23. S = -, T = -;
  24.  
  25. int id, maxi, ret = ;
  26.  
  27. for (int i = ; i < n; ++i)
  28. {
  29. maxi = -inf;
  30.  
  31. for (int j = ; j < n; ++j)
  32. if (!com[j] && !vis[j] && wet[j] > maxi)
  33. id = j, maxi = wet[j];
  34.  
  35. if (id == T)
  36. return ret;
  37.  
  38. S = T;
  39. T = id;
  40. ret = maxi;
  41. vis[id] = ;
  42.  
  43. for (int j = ; j < n; ++j)
  44. if (!com[j] && !vis[j])
  45. wet[j] += G[id][j];
  46. }
  47. }
  48.  
  49. inline int StoerWagner(void)
  50. {
  51. int ret = inf, S, T;
  52.  
  53. memset(com, , sizeof(com));
  54.  
  55. for (int i = ; i < n - ; ++i)
  56. {
  57. ret = min(ret, search(S, T));
  58.  
  59. if (!ret)return ;
  60.  
  61. com[T] = ;
  62.  
  63. for (int j = ; j < n; ++j)
  64. if (!com[j])
  65. G[S][j] += G[T][j],
  66. G[j][S] += G[j][T];
  67. }
  68.  
  69. return ret;
  70. }
  71.  
  72. signed main(void)
  73. {
  74. while (~scanf("%d%d", &n, &m))
  75. {
  76. memset(G, , sizeof(G));
  77.  
  78. for (int i = ; i <= m; ++i)
  79. {
  80. int x, y, w;
  81. scanf("%d%d%d", &x, &y, &w);
  82. G[x][y] += w;
  83. G[y][x] += w;
  84. }
  85.  
  86. printf("%d\n", StoerWagner());
  87. }
  88. }

@Author: YouSiki

POJ Minimum Cut的更多相关文章

  1. POJ 2914 Minimum Cut

    Minimum Cut Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 9319   Accepted: 3910 Case ...

  2. POJ 2914 Minimum Cut 最小割图论

    Description Given an undirected graph, in which two vertices can be connected by multiple edges, wha ...

  3. POJ2914 Minimum Cut —— 最小割

    题目链接:http://poj.org/problem?id=2914 Minimum Cut Time Limit: 10000MS   Memory Limit: 65536K Total Sub ...

  4. hdu 5452 Minimum Cut 树形dp

    Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...

  5. poj Minimum( CutStoer Wagner算法)

    Minimum Cut 题目: 给出一张图.要求你删除最小割权和图. 算法分析: ////////////////////     转载 --- ylfdrib   ///////////////// ...

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

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

  7. 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 ...

  8. Smallest Minimum Cut HDU - 6214(最小割集)

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

  9. 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 ...

随机推荐

  1. logstash+elasticsearch+kibana管理日志(安装)

    logstash1.先安装jdk2.wget https://download.elastic.co/logstash/logstash/logstash-2.4.0.tar.gz tar -xzvf ...

  2. JQuery中隐藏/显示事件函数

    1.$("button").click(function(){ $("p").hide(); });2.如果您的网站包含许多页面,并且您希望您的 jQuery ...

  3. 从 HTTP 到 HTTPS - 什么是 HTTPS

    这篇文章首发于我的个人网站:听说 - https://tasaid.com/,建议在我的个人网站阅读,拥有更好的阅读体验. 这篇文章与 博客园 和 Segmentfault 共享. 前端开发QQ群:3 ...

  4. Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置

    一. 下载资料 1. JDK 1.6 + 2. Scala 2.10.4 3. Hadoop 2.6.4 4. Spark 1.6 二.预先安装 1. 安装JDK 2. 安装Scala 2.10.4 ...

  5. iOS之在写一个iOS应用之前必须做的7件事(附相关资源)

    本文由CocoaChina--不再犹豫(tao200610704@126.com)翻译 作者:@NIkant Vohra 原文:7 Things you must absolutely do befo ...

  6. 信息系统实践手记5-CACHE设计一例

    说明:信息系统实践手记系列是系笔者在平时研发中先后遇到的大小的问题,也许朴实和细微,但往往却是经常遇到的问题.笔者对其中比较典型的加以收集,描述,归纳和分享. 摘要:此文描述了笔者接触过的部分信息系统 ...

  7. C#语言基础——函数

    函数一个较大的程序一般应分为若干个程序块,每一个模块用来实现一个特定的功能.所有的高级语言中都有子程序这个概念,用子程序实现模块的功能.在C#语言中,子程序的作用是由一个主函数和若干个函数构成.由主函 ...

  8. php类中的魔术方法

    1.构造函数 析构函数class pt{ function __construct($data) { echo "pt is start ..."; $this->pr($d ...

  9. python-socket模块

    socket server #!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('127.0.0.1',9999 ...

  10. ubuntu下修改键位

    尴尬的背景: 服役5年的笔记本,最近键盘失灵,部分键位彻底失去响应.最蛋疼的是左右方向键都不能用了 ○| ̄|_ 解决方案是,通过xmodmap命令,用其他相对鸡肋些的键位替代方向键. 1 查看各个键位 ...