全局最小割 poj2914 Minimum Cut
来源:互联网 发布:刷高中生物的软件 编辑:程序博客网 时间:2024/05/29 19:19
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 M integersA, 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 30 1 11 2 12 0 14 30 1 11 2 12 3 18 140 1 10 2 10 3 11 2 11 3 12 3 14 5 14 6 14 7 15 6 15 7 16 7 14 0 17 3 1
Sample Output
212
#include <iostream>#include <cstdio>#include <cstring>#define MAXN 505#define INF 1000000000using namespace std;int map[MAXN][MAXN];int v[MAXN], dis[MAXN];bool vis[MAXN];int Stoer_Wagner(int n){ int i, j, res = INF; for(i = 0; i < n; i ++) v[i] = i; while(n > 1) { int k, pre = 0; memset(vis, 0, sizeof(vis)); memset(dis, 0, sizeof(dis)); for(i = 1; i < n; i ++) { k = -1; for(j = 1; j < n; j ++) if(!vis[v[j]]) { dis[v[j]] += map[v[pre]][v[j]]; if(k == -1 || dis[v[k]] < dis[v[j]]) k = j; } vis[v[k]] = true; if(i == n - 1) { res = min(res, dis[v[k]]); for(j = 0; j < n; j ++) { map[v[pre]][v[j]] += map[v[j]][v[k]]; map[v[j]][v[pre]] += map[v[j]][v[k]]; } v[k] = v[-- n]; } pre = k; } } return res;}int main(){ int n, m, u, v, w; while(scanf("%d%d", &n, &m) != EOF) { memset(map, 0, sizeof(map)); while(m --) { scanf("%d%d%d", &u, &v, &w); map[u][v] += w; map[v][u] += w; } printf("%d\n", Stoer_Wagner(n)); } return 0;}
- 全局最小割 poj2914 Minimum Cut
- POJ2914 Minimum Cut 【全局最小割】(Stoer_Wagner)
- POJ2914 Minimum Cut【全局最小割】【Stoer-Wangner】
- 【POJ2914】Minimum Cut-无向图的全局最小割
- POJ2914 Minimum Cut 【全局最小割Stoer-Wagner模板题】
- POJ2914 Minimum Cut 最小割集
- POJ2914 Minimum Cut(最小割模板题)
- POJ2914 Minimum Cut(最小割)
- POJ2914 Minimum Cut —— 最小割
- poj2914 全局最小割
- poj2914——Minimum Cut//最小割Stoer_Wagner
- POJ 2914 Minimum Cut 全局最小割
- poj 2914 Minimum Cut(全局最小割)
- POJ 2914 Minimum Cut 全局最小割
- POJ 2914 Minimum Cut 全局最小割
- 全局最小割模板 poj2914
- POJ2914 Minimum Cut(无向图的最小割,Stoer_Wagner算法)
- POJ 2914 Minimum Cut Stoer-Wagner(全局最小割)
- 一个Log系统,客户端运行起来,排除那些可以输出(dll文件)
- 《Effective Javascript》
- android 对已知路径下图片进行压缩
- android在下载app后自动安装,安装完成后不会弹出打开或完成界面
- html中图片上传预览功能
- 全局最小割 poj2914 Minimum Cut
- Linux 下wait函数详解
- UTF-8编码)将字符串写入文件,当字符串中包含中文时,出现写入文件的数据残缺,而当不包含中文时,写入文件的数据正常
- CookieUtils工具类
- declspec的用法小结
- 聊天室入门实战(node,sockte.io实现)--第三章(在线成员列表及头像显示,单聊)
- Ubuntu 主题美化
- vux的生命周期自己总结规律
- 智能指针的交叉引用