POJ Minimum Cut
Minimum Cut
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 A, B and C (0 ≤ A, B < N, A ≠ B, C > 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 Sample Output 2 Source |
[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的更多相关文章
- POJ 2914 Minimum Cut
Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 9319 Accepted: 3910 Case ...
- POJ 2914 Minimum Cut 最小割图论
Description Given an undirected graph, in which two vertices can be connected by multiple edges, wha ...
- POJ2914 Minimum Cut —— 最小割
题目链接:http://poj.org/problem?id=2914 Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Sub ...
- hdu 5452 Minimum Cut 树形dp
Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...
- poj Minimum( CutStoer Wagner算法)
Minimum Cut 题目: 给出一张图.要求你删除最小割权和图. 算法分析: //////////////////// 转载 --- ylfdrib ///////////////// ...
- HDU 6214.Smallest Minimum Cut 最少边数最小割
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- 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 ...
- Smallest Minimum Cut HDU - 6214(最小割集)
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- 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 ...
随机推荐
- JAVA调用R
JAVA很适合开发应用系统,但是数学建模和计算能力非其所长,如果该系统需要进行大量的统计或者优化的计算,调用R是一种很好的方式.JAVA负责系统的构建,R用来做运算引擎,从而实现应用型和分析性相结合的 ...
- 关于Three.js基本几何形状之SphereGeometry球体学习
一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...
- C++01.类的引入
1.假设我们要输出张三,李四两个人的基本信息,包括姓名,年龄,可以用以下的C程序实现: eg: #include <stdio.h> int main(int argc,char **ar ...
- 开发属于自己的yeoman脚手架(generator-reactpackage)
自从前后端开始分离之后,前端项目工程化也显得越来越重要了,之前写过一篇搭建基于Angular+Requirejs+Grunt的前端项目教程,有兴趣的可以点这里去看 但是有些项目可以使用这种方式,但有些 ...
- JQuery使用deferreds串行多个ajax请求
使用JQuery对多个ajax请求串行执行. HTML代码: <a href="#">Click me!</a> <div></div&g ...
- Oracle数据库的链接数目超标
测试场景:Oracle数据库的链接数目超标,iServer是否自动连接. 测试步骤:(1)设置了最大连接数为85,oracle后台进程有83:(2)开启3台iserver(A,B,C)A,B发布tes ...
- Android GZIP压缩IO流,优化APP数据传输(一)
我是小搬运工,今天讲解流的压缩传输 在我们安卓开发中,通常伴随着大量的数据传输,在此,楼主给出一个简单的压缩流的数据进行操作. public void GZIPCpf(String path) { / ...
- EF里如何定制实体的验证规则和实现IObjectWithState接口进行验证以及多个实体的同时验证
之前的Code First系列文章已经演示了如何使用Fluent API和Data Annotation的方式配置实体的属性,比如配置Destination类的Name属性长度不大于50等.本文介绍E ...
- WebServices:WSDL的结构分析
WSDL(Web Services Description Language,Web服务描述语言)是为描述Web Services发布的XML格式.W3C组织没有批准1.1版的WSDL,但是2.0版本 ...
- python 多进程使用总结
python中的多进程主要使用到 multiprocessing 这个库.这个库在使用 multiprocessing.Manager().Queue时会出问题,建议大家升级到高版本python,如2 ...