题目链接: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. Error处理: “非法字符: \65279”的解决办法

    将eclipse项目转为maven项目的时候,编译时遇到 “非法字符: \65279”的报错. 出错内容是: *.java:1: 非法字符: \65279    [javac] package com ...

  2. 使用plantuml生成uml图

    主要包括以下三步: 一.到http://plantuml.com/download 下载plantuml.jar ,我将这个软件放置到home的/home/munication/WORKM/Progr ...

  3. C++ 使用成员初始化列表的一个小坑

    注意在成员列表中初始化的顺序并不是列表顺序 而是: 在类中声明的顺序! EventLoop::EventLoop() :looping(false), quit(false),_tid(curThre ...

  4. Js 流程控制

    流程控制 顺序.分支.循环 顺序结构 代码一行一行从上往下执行并解析 分支结构 if语句 switch语句 if语句 单分支 if(条件表达式){ //语句块 } 含义:当条件表达式为真的时候就执行里 ...

  5. collection包1.1.0都升级了什么功能

    collection包1.1.0都升级了什么功能 jianfengye/collection(https://github.com/jianfengye/collection) 这个包喜迎第一个子版本 ...

  6. codevs——2370 小机房的树

    2370 小机房的树  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 小机房有棵焕狗种的树,树上有N个 ...

  7. 洛谷P1061 Jam的计数法

    题目描述 Jam是个喜欢标新立异的科学怪人.他不使用阿拉伯数字计数,而是使用小写英文字母计数,他觉得这样做,会使世界更加丰富多彩.在他的计数法中,每个数字的位数都是相同的(使用相同个数的字母),英文字 ...

  8. Springboot 工具类静态注入

    用springboot搭了一个项目,里面要用到一个DictUtils,因为要用到DictMapper,在百度找了一些方法,最后用下面的方法能成功获取到DictMapper @Component pub ...

  9. 图片异步载入之 Android-Universal-Image-Loader

    今天在做项目的时候用了之前写的图片载入类.尽管也能实现缓存什么的.可是在载入大图的时候非常慢非常慢.于是上网找解决方式,准备优化一下,无意中发现了Android-Universal-Image-Loa ...

  10. HTML--比较实用的小例子

    常用的前端实例: 1略 2.在网页商城中的图片当我们把鼠标放上去之后,图片会显示一个有颜色的外边框,图片某一部分的字体的颜色并发生改变 鼠标放上去之前 鼠标放上去之后: 实现的代码: <!DOC ...