题目链接:http://poj.org/problem?id=2914

Minimum Cut
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 10117   Accepted: 4226
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 M integers 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)

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXN = +; int mp[MAXN][MAXN];
bool combine[MAXN];
int n, m; bool vis[MAXN];
int w[MAXN];
int prim(int times, int &s, int &t) //最大生成树?
{
memset(w,,sizeof(w));
memset(vis,,sizeof(vis));
for(int i = ; i<=times; i++) //times为实际的顶点个数
{
int k, maxx = -INF;
for(int j = ; j<n; j++)
if(!vis[j] && !combine[j] && w[j]>maxx)
maxx = w[k=j]; vis[k] = ;
s = t; t = k;
for(int j = ; j<n; j++)
if(!vis[j] && !combine[j])
w[j] += mp[k][j];
}
return w[t];
} int mincut()
{
int ans = INF;
memset(combine,,sizeof(combine));
for(int i = n; i>=; i--) //每一次循环,就减少一个点
{
int s, t;
int tmp = prim(i, s, t);
ans = min(ans, tmp);
combine[t] = ;
for(int j = ; j<n; j++) //把t点删掉,与t相连的边并入s
{
mp[s][j] += mp[t][j];
mp[j][s] += mp[j][t];
}
}
return ans;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(mp,,sizeof(mp));
for(int i = ; i<=m; i++)
{
int u, v, w;
scanf("%d%d%d",&u,&v,&w);
mp[u][v] += w;
mp[v][u] += w;
}
cout<< mincut() <<endl;
}
return ;
}

POJ2914 Minimum Cut —— 最小割的更多相关文章

  1. POJ 2914 Minimum Cut 最小割图论

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

  2. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  3. HDU 6214 Smallest Minimum Cut (最小割且边数最少)

    题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...

  4. POJ 2914 Minimum Cut 最小割算法题解

    最标准的最小割算法应用题目. 核心思想就是缩边:先缩小最大的边.然后缩小次大的边.依此缩小 基础算法:Prime最小生成树算法 只是本题測试的数据好像怪怪的,相同的算法时间执行会区别非常大,并且一样的 ...

  5. poj2914 Minimum Cut 全局最小割模板题

    Minimum Cut Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 8324   Accepted: 3488 Case ...

  6. poj2914无向图的最小割模板

    题意:给出无向图的点,边,权值.求最小割. 思路:根据题目规模,最大流算法会超时. 网上参考的模板代码. 代码: /*最小割集◎Stoer-Wagner算法:一个无向连通网络,去掉一个边集可以使其变成 ...

  7. poj2914无向图的最小割

    http://blog.csdn.net/vsooda/article/details/7397449 //算法理论 http://www.cnblogs.com/ylfdrib/archive/20 ...

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

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

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

随机推荐

  1. 填报志愿(codevs 2930)

    题目描述 Description 高考已经结束,而志愿填报正在进行中- 吴校长的学校里有n位同学,每位同学有ki个愿意去的大学.而在吴老师的省份中,有m所大学有招生名额.根据往年的经验,对于每所大学( ...

  2. 假几何真逆序数 NB HDU3465

    题意: 有n条直线,问他们两两在横坐标开区间(L,R)之间相交的个数 n=50000,暴力肯定就不用想了,如果在纸上画一画可以发现如果两条直线在(L,R)内相交,那么他们与x= L和x=R的交点序数是 ...

  3. 建筑抢修 BZOJ 1029

    建筑抢修 [问题描述] 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修 ...

  4. C# 判断上传图片是否被PS修改过的方法

    今天在网上发现一个判断图片是否被Photoshop修改过的方法.发现还不错,呵呵.摘录下来. 讲下基本的原理:其实每张被photoshop修改过的图片都会有Adobe Photoshop这样的字样在图 ...

  5. css-包含块

    在CSS中,有事一个元素的位置和尺寸的计算都相对于一个矩形,这个矩形被称作包含块.包含块是一个相对的概念,比如 子元素的初始化布局总是在父元素的左上角,这就是一个相对的概念.其中父元素就是一个参照物, ...

  6. 属性font-family:Font property font-family does not have generic default

    以前定义字体都是用的常用的字体,也没注意过会有这个提示,昨天在写界面的时候重新定义了一个本地没有的字体,发现会有提示. W3C的文档: font-family:<family-name>, ...

  7. 高性能mysql之schema与数据类型优化

    1.数据类型 http://www.cnblogs.com/YDDMAX/p/4937770.html

  8. java.nio.ByteBuffer 以及flip,clear及rewind区别

    Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...

  9. decorate all function in all module

    需求: 有package db_api,其下有很多 module 如 plane.py ship.py ufo.py.这些module内定义了方法如 plane.fly(), ship.float() ...

  10. java多线程异步执行

    import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.ut ...