POJ Minimum Cut
|
Minimum Cut
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 Mintegers 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 Sample Output 2 Source |
|||||||||
[Submit] [Go Back] [Status] [Discuss]
无向图的边连通度,有一个神奇的算法,还有我蒟蒻的模板。
#include <cstdio>
#include <cstring> inline int min(int a, int b)
{
return a < b ? a : b;
} const int inf = 2e9;
const int maxn = ; int n, m;
int vis[maxn];
int wet[maxn];
int com[maxn];
int G[maxn][maxn]; inline int search(int &S, int &T)
{
memset(vis, , sizeof(vis));
memset(wet, , sizeof(wet)); S = -, T = -; int id, maxi, ret = ; for (int i = ; i < n; ++i)
{
maxi = -inf; for (int j = ; j < n; ++j)
if (!com[j] && !vis[j] && wet[j] > maxi)
id = j, maxi = wet[j]; if (id == T)
return ret; S = T;
T = id;
ret = maxi;
vis[id] = ; for (int j = ; j < n; ++j)
if (!com[j] && !vis[j])
wet[j] += G[id][j];
}
} inline int StoerWagner(void)
{
int ret = inf, S, T; memset(com, , sizeof(com)); for (int i = ; i < n - ; ++i)
{
ret = min(ret, search(S, T)); if (!ret)return ; com[T] = ; for (int j = ; j < n; ++j)
if (!com[j])
G[S][j] += G[T][j],
G[j][S] += G[j][T];
} return ret;
} signed main(void)
{
while (~scanf("%d%d", &n, &m))
{
memset(G, , sizeof(G)); for (int i = ; i <= m; ++i)
{
int x, y, w;
scanf("%d%d%d", &x, &y, &w);
G[x][y] += w;
G[y][x] += w;
} printf("%d\n", StoerWagner());
}
}
@Author: YouSiki
POJ Minimum Cut的更多相关文章
- POJ 2914 Minimum Cut
Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 9319 Accepted: 3910 Case ...
- POJ 2914 Minimum Cut 最小割图论
Description Given an undirected graph, in which two vertices can be connected by multiple edges, wha ...
- POJ2914 Minimum Cut —— 最小割
题目链接:http://poj.org/problem?id=2914 Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Sub ...
- hdu 5452 Minimum Cut 树形dp
Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...
- poj Minimum( CutStoer Wagner算法)
Minimum Cut 题目: 给出一张图.要求你删除最小割权和图. 算法分析: //////////////////// 转载 --- ylfdrib ///////////////// ...
- 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 ...
- Smallest Minimum Cut HDU - 6214(最小割集)
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- HDU - 6214:Smallest Minimum Cut(最小割边最小割)
Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes ...
随机推荐
- PHP 适配器模式
适配器模式(Adapter)模式:将一个类的接口,转换成客户期望的另一个类的接口.适配器让原本接口不兼容的类可以合作无间. [适配器模式中主要角色]目标(Target)角色:定义客户端使用的与 ...
- Atitit.可视化与报表原理与概论
Atitit.可视化与报表原理与概论 1. 信息可视化1 2. Gui可视化1 3. 报表系统(三大图表,金字塔,组织结构图等)1 4. <可视化数据>目录3 5. 可视化的具体实现(c ...
- Waud.js – 使用HTML5降级处理的Web音频库
Waud.js 是一个Web音频库,有一个HTML5音频降级处理方案. 它允许您利用Web音频API为你的Web应用程序控制音频功能.在不支持Web音频API的非现代浏览器使用HTML5音频降级方案. ...
- JSON.parse与eval的区别
JSON.parse与eval和能将一个字符串解析成一个JSON对象,但还是有挺大区别. 测试代码 var A = "{ a: 1 , b : 'hello' }"; var B ...
- jQuery orbit 幻灯片
在线实例 默认 带缩略图 带描述 使用方法 <div class="wrap" style="width: 565px; height: 290px; margin ...
- iOS之按钮出现时加一个动画效果
//按钮出现时的动画效果 + (void)buttonAnimation:(UIButton *)sender { CAKeyframeAnimation *animation = [CAKeyfra ...
- IOS-小项目(饿了么 网络部分 简单实现)
在介绍小项目之前,在此说明一下此代码并非本人所写,我只是随笔的整理者. 在介绍之前先展现一下效果图. 看过效果图大家应该很熟悉了,就是饿了么的一个界面而已,值得注意的是,实现时并没有采用本地连接,而是 ...
- 详解java定时任务
在我们编程过程中如果需要执行一些简单的定时任务,无须做复杂的控制,我们可以考虑使用JDK中的Timer定时任务来实现.下面LZ就其原理.实例以及Timer缺陷三个方面来解析JavaTimer定时器. ...
- 记录一次Quartz2D学习(二)
(一)内主要就是讲了线条的绘制以及绘制状态的保存与恢复 本次就讲一些图形的画法 2 图形的绘制 2.1 三角形的绘制 :(就是绘制三条线) - (void)drawRect:(CGRect)rect ...
- HTTP Session、Cookie机制详解
一.什么是http session,有什么用 HTTP协议本身是无状态的,本身并不能支持服务端保存客户端的状态信息,于是,Web Server中引入了session的概念,用来保存客户端的状态信息. ...