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

3 3
0 1 1
1 2 1
2 0 1
4 3
0 1 1
1 2 1
2 3 1
8 14
0 1 1
0 2 1
0 3 1
1 2 1
1 3 1
2 3 1
4 5 1
4 6 1
4 7 1
5 6 1
5 7 1
6 7 1
4 0 1
7 3 1

Sample Output

2
1
2

Source

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

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

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

 #include <cstdio>
#include <cstring> inline int min(int a, int b)
{
return a < b ? a : b;
} const int inf = 2e9;
const int maxn = ; int n, m;
int vis[maxn];
int wet[maxn];
int com[maxn];
int G[maxn][maxn]; inline int search(int &S, int &T)
{
memset(vis, , sizeof(vis));
memset(wet, , sizeof(wet)); S = -, T = -; int id, maxi, ret = ; for (int i = ; i < n; ++i)
{
maxi = -inf; for (int j = ; j < n; ++j)
if (!com[j] && !vis[j] && wet[j] > maxi)
id = j, maxi = wet[j]; if (id == T)
return ret; S = T;
T = id;
ret = maxi;
vis[id] = ; for (int j = ; j < n; ++j)
if (!com[j] && !vis[j])
wet[j] += G[id][j];
}
} inline int StoerWagner(void)
{
int ret = inf, S, T; memset(com, , sizeof(com)); for (int i = ; i < n - ; ++i)
{
ret = min(ret, search(S, T)); if (!ret)return ; com[T] = ; for (int j = ; j < n; ++j)
if (!com[j])
G[S][j] += G[T][j],
G[j][S] += G[j][T];
} return ret;
} signed main(void)
{
while (~scanf("%d%d", &n, &m))
{
memset(G, , sizeof(G)); for (int i = ; i <= m; ++i)
{
int x, y, w;
scanf("%d%d%d", &x, &y, &w);
G[x][y] += w;
G[y][x] += w;
} printf("%d\n", StoerWagner());
}
}

@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. JAVA调用R

    JAVA很适合开发应用系统,但是数学建模和计算能力非其所长,如果该系统需要进行大量的统计或者优化的计算,调用R是一种很好的方式.JAVA负责系统的构建,R用来做运算引擎,从而实现应用型和分析性相结合的 ...

  2. 关于Three.js基本几何形状之SphereGeometry球体学习

    一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...

  3. C++01.类的引入

    1.假设我们要输出张三,李四两个人的基本信息,包括姓名,年龄,可以用以下的C程序实现: eg: #include <stdio.h> int main(int argc,char **ar ...

  4. 开发属于自己的yeoman脚手架(generator-reactpackage)

    自从前后端开始分离之后,前端项目工程化也显得越来越重要了,之前写过一篇搭建基于Angular+Requirejs+Grunt的前端项目教程,有兴趣的可以点这里去看 但是有些项目可以使用这种方式,但有些 ...

  5. JQuery使用deferreds串行多个ajax请求

    使用JQuery对多个ajax请求串行执行. HTML代码: <a href="#">Click me!</a> <div></div&g ...

  6. Oracle数据库的链接数目超标

    测试场景:Oracle数据库的链接数目超标,iServer是否自动连接. 测试步骤:(1)设置了最大连接数为85,oracle后台进程有83:(2)开启3台iserver(A,B,C)A,B发布tes ...

  7. Android GZIP压缩IO流,优化APP数据传输(一)

    我是小搬运工,今天讲解流的压缩传输 在我们安卓开发中,通常伴随着大量的数据传输,在此,楼主给出一个简单的压缩流的数据进行操作. public void GZIPCpf(String path) { / ...

  8. EF里如何定制实体的验证规则和实现IObjectWithState接口进行验证以及多个实体的同时验证

    之前的Code First系列文章已经演示了如何使用Fluent API和Data Annotation的方式配置实体的属性,比如配置Destination类的Name属性长度不大于50等.本文介绍E ...

  9. WebServices:WSDL的结构分析

    WSDL(Web Services Description Language,Web服务描述语言)是为描述Web Services发布的XML格式.W3C组织没有批准1.1版的WSDL,但是2.0版本 ...

  10. python 多进程使用总结

    python中的多进程主要使用到 multiprocessing 这个库.这个库在使用 multiprocessing.Manager().Queue时会出问题,建议大家升级到高版本python,如2 ...