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 ...
随机推荐
- Mac 下使用homebrew 安装node后全局安装找不到问题
Homebrew 是mac上的包管理工具,其官网: http://brew.sh/ 在使用brew安装node之后安装一些常见工具比如 gulp npm install -g gulp 提示安装成功之 ...
- Scala 包
包的绝对地址_root_.开始 如_root_.scala.collection.mutable.ArrayBuffer
- Android将应用调试log信息保存在SD卡
转载:http://blog.csdn.net/way_ping_li/article/details/8487866 把自己应用的调试信息写入到SD卡中. package com.sdmc.hote ...
- 【转】iOS UIApplication详解
1.状态栏UIStateBar的设置是在UIApplication里面设置的,它包含4中风格 2. - (void)beginIgnoringInteractionEvents; (void)endI ...
- 简单好记的Jdk 环境变量配置
- iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser
iOS9之后,默认网络请求是https,所有我们要设置一下网络安全,具体设置如下 1.第三方类库 XMLDictionary 下载地址: https://github.com/nicklockwood ...
- Laravel大型项目系列教程(五)之文章和标签管理
一.前言 本节教程将大概完成文章和标签管理以及标签关联. 二.Let's go 1.文章管理 首先创建管理后台文章列表视图: $ php artisan generate:view admin.art ...
- [Erlang 0112] Elixir Protocols
Why Elixir 为什么要学习Elixir?答案很简单,为了更好的学习Erlang.这么无厘头的理由? Erlang语法设计几乎没有考虑过取悦开发者,所以学习之初的门槛略高.对于已经克服了最初 ...
- Oracle学习笔记三 SQL命令
SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)
- 两个js文件之间函数互调问题
按照常理来说,在<body>标签结束之前以下面的方式引入两个js文件 <script src="a.js"></script> <scri ...