POJ-2914 Minimum Cut(全局最小割)
来源:互联网 发布:数据库安全管理制度 编辑:程序博客网 时间:2024/06/05 09:21
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 integers 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 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模板题,找出一个图中的最小割使得整个图分成2个联通块
#include<cstdio>#include<string.h>#include<queue>#include<algorithm>using namespace std;const int MX = 505;const int inf = 0x3f3f3f3f;struct Stoer_Wagner { int mp[MX][MX], s, t; int v[MX], d[MX]; void init(int n) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) mp[i][j] = 0; } void add(int u, int v, int w) { mp[u][v] += w; mp[v][u] += w; } int solve(int n) { int i, j, now, ret = inf; for (i = 0; i < n; i++)v[i] = i;//下标从0开始 while (n > 1) { for (now = 0, i = 1; i < n; i++) d[v[i]] = 0; for (i = 1; i < n; i++) { swap(v[now], v[i - 1]); for (now = j = i; j < n; j++) { d[v[j]] += mp[v[i - 1]][v[j]]; if (d[v[now]] < d[v[j]])now = j; } } if (ret > d[v[now]]) { ret = d[v[now]]; s = v[now - 1]; t = v[now]; } for (j = 0; j < n; j++) mp[v[j]][v[now - 1]] = mp[v[now - 1]][v[j]] += mp[v[j]][v[now]]; v[now] = v[--n]; } return ret; }} F;
- POJ 2914 Minimum Cut 全局最小割
- poj 2914 Minimum Cut(全局最小割)
- POJ 2914 Minimum Cut 全局最小割
- POJ 2914 Minimum Cut 全局最小割
- POJ 2914 Minimum Cut Stoer-Wagner(全局最小割)
- poj 2914 Minimum Cut(全局最小割)
- POJ-2914 Minimum Cut(全局最小割)
- POJ 2914 Minimum Cut 最小割集Stoer-Wagner算法(全局最小割)
- POJ 2914 Minimum Cut 最小割
- 【最小割】POJ-2914 Minimum Cut
- poj 2914 Minimum Cut(无向图最小割)
- POJ 2914-Minimum Cut(Stoer_Wagner最小割算法)
- POJ 2914 Minimum Cut (最小割模板题)
- poj 2914 Minimum Cut 【无向图全局最小割 Stoer-wagner算法】
- POJ2914 Minimum Cut 【全局最小割】(Stoer_Wagner)
- 全局最小割 poj2914 Minimum Cut
- POJ 2914 Minimum Cut //无向图求最小割
- poj 2914 Minimum Cut 无向图最小割
- linux gem手动安装
- 笔试题判断字符串是否是回文
- 【OpenPose-Windows】运行OpenposeDemo.exe 如何保存图像运行结果及关节点信息
- Linux RubyGems介绍和使用
- 数据库常用指令
- POJ-2914 Minimum Cut(全局最小割)
- 二维数组中的查找
- brew、gem、npm介绍
- 设计模式-装饰者模式 C++实现
- ubuntu下搭建redis集群
- #CTFWEB#对一道入门题的思考
- Linux zip unzip安装
- 欲戴皇冠 必承其重
- Error:(27, 0) Gradle DSL method not found: 'compileSdkVersion()'