POJ2914 Minimum Cut —— 最小割
题目链接:http://poj.org/problem?id=2914
| 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 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
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
代码如下:
#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 —— 最小割的更多相关文章
- POJ 2914 Minimum Cut 最小割图论
Description Given an undirected graph, in which two vertices can be connected by multiple edges, wha ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- HDU 6214 Smallest Minimum Cut (最小割且边数最少)
题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...
- POJ 2914 Minimum Cut 最小割算法题解
最标准的最小割算法应用题目. 核心思想就是缩边:先缩小最大的边.然后缩小次大的边.依此缩小 基础算法:Prime最小生成树算法 只是本题測试的数据好像怪怪的,相同的算法时间执行会区别非常大,并且一样的 ...
- poj2914 Minimum Cut 全局最小割模板题
Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 8324 Accepted: 3488 Case ...
- poj2914无向图的最小割模板
题意:给出无向图的点,边,权值.求最小割. 思路:根据题目规模,最大流算法会超时. 网上参考的模板代码. 代码: /*最小割集◎Stoer-Wagner算法:一个无向连通网络,去掉一个边集可以使其变成 ...
- poj2914无向图的最小割
http://blog.csdn.net/vsooda/article/details/7397449 //算法理论 http://www.cnblogs.com/ylfdrib/archive/20 ...
- 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 ...
随机推荐
- UVa1363 Joseph's Problem
把整个序列进行拆分成[k,k/2),[k/2, k/3), [k/3,k/4)...k[k/a, k/b)的形式,对于k/i(整除)相同的项,k%i成等差数列. /*by SilverN*/ #inc ...
- 【Hihocoder1034】毁灭者问题(splay,树状数组)
题意: 假设你拥有 n 个魔法单位,他们从左到有站在一行,编号从 1 到 n. 每个单位拥有三项属性: si: 初始法力. mi: 最大法力上限. ri: 每秒中法力回复速度. 现在你操纵一个毁灭者, ...
- Xcode6 pch文件
XCode6里, 默认是没有pch文件的,如果我们想使用pch文件,需要手动添加,添加步骤如下 1.在XCode6中是么有pch文件的,如下图 2.创建pch文件 3.配置pch文件 ...
- linux命令netstat或ifconfig未找到
linux命令netstat或ifconfig未找到 linux使用netstat或者ifconfig命令时,显示命令未找到.通过yum search netstat这个命令,匹配结果如下:===== ...
- 记住密码后,密码框Password会自动带出数据
一般登陆之后浏览器会询问是否记住密码,如果把密码记住在浏览器上,下次登陆的时候浏览器会把用户名和密码自动填充到登录页面.前段时间服务站平台的员工账号模块提测后,测试提出360浏览器记住密码后会自用把登 ...
- webStorm汉化
http://www.sdbeta.com/xiazai/2015/0603/35070.html 注册时选择“License server”输入“http://idea.imsxm.com/”点击“ ...
- 使用icomoon把svg图片生成字体图标
今天看了使用icomoon来将svg转换成图标字体,本来是不会使用别人给的svg,也不清楚具体的好处是什么,查了svg以后,越来越懵,svg挺好的为什么要转成图标字体呢. 一.SVG介绍 SVG 是一 ...
- vue之组件理解(一)
组件是可复用的 Vue 实例,所以它们与 new Vue 接收相同的选项,例如 data.computed.watch.methods 以及生命周期钩子等.仅有的例外是像 el 这样根实例特有的选项. ...
- 关于Java基础的一些笔试题总结
针对近期腾讯.京东.网易等公司的笔试,遇到一些有关Java基础的问题,在此总结,希望能通过这几道经典问题题发散,举一反三,借此打牢基础!自己总结,望提出宝贵意见! 一.关于null的一道小题 先开开 ...
- vmware Unable to open kernel device "\\.\Global\vmx86": The system cannot find the file 的解决方法
https://communities.vmware.com/thread/245800?start=0&tstart=0 I have exactly same issue. I star ...