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 ...
随机推荐
- java面试题——集合框架
先来看一下集合框架关系图 Collection FrameWork 如下: Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └S ...
- 【原】JAVA开发环境搭建
1.JDK下载并安装,以jdk-7u45-windows-i586.exe为例(注意JDK的安装和JRE的安装是分开的) 2.“我的电脑”右键属性,找到“高级系统设置”,找到“高级”tab下的“环境变 ...
- 基于rem的移动端自适应解决方案
代码有更新,最好直接查看github: https://github.com/finance-sh/adaptive adaptivejs原理: 利用rem布局,根据公式 html元素字体大小 = d ...
- Array&String总结
每一部分总结后有实例代码,代码中黄色框方法不改变原数组.PS:所有实例结果均一一运行所得. 符号说明: array和string共享 参数 Array --普通方法 栈: pop() p ...
- 当Eclipse报版本低时的处理方法
http://blog.sina.com.cn/s/blog_6f0c85e10100v6pv.html 更新到API12的时候出过问题,这一次难免又会出现了,不过我的版本还真全啊,哇咔咔~ 这里 ...
- 常用的SQL语句
使用prepareStatement对象执行的增.删.改.查sql语句: 查: String sql = "SELECT * FROM 表名 WHERE loginId=? AND pas ...
- html 概念
HTML 超文本标记语言,标准通用标记语言下的一个应用.http://baike.baidu.com/link?url=RYF4Pj7VUPifcXatU7OJLGRljIgkp4MjzkspARor ...
- 探索逻辑事务 TransactionScope
一.什么是TransactionScope? TransactionScope即范围事务(类似数据库中的事务),保证事务声明范围内的一切数据修改操作状态一致性,要么全部成功,要么全部失败回滚. MSD ...
- 机器学习实战笔记(Python实现)-05-支持向量机(SVM)
--------------------------------------------------------------------------------------- 本系列文章为<机器 ...
- [Hadoop in Action] 第4章 编写MapReduce基础程序
基于hadoop的专利数据处理示例 MapReduce程序框架 用于计数统计的MapReduce基础程序 支持用脚本语言编写MapReduce程序的hadoop流式API 用于提升性能的Combine ...