HDU 3002
无向图最小割。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int MAXN=;
const int inf=;
int vis[MAXN],combine[MAXN],wan[MAXN];
int map[MAXN][MAXN];
int n,m,t;
int mincut,S,T; void seacut(){
int Max; int p;
S=T=-;
memset(vis,,sizeof(vis));
memset(wan,,sizeof(wan));
for(int i=;i<n;i++){
Max=-inf;
for(int j=;j<n;j++){
if(!combine[j]&&!vis[j]&&wan[j]>Max){
Max=wan[j]; p=j;
}
}
// cout<<p<<endl;
if(p==T) return;
S=T;T=p;
vis[T]=;
for(int j=;j<n;j++){
if(!combine[j]&&!vis[j]){
wan[j]+=map[T][j];
}
}
}
} void storewanger(){
mincut=inf;
memset(combine,,sizeof(combine));
for(int i=;i<n-;i++){
seacut();
if(wan[T]<mincut) mincut=wan[T];
if(mincut==) return;
combine[T]=;
for(int j=;j<n;j++){
if(!combine[j]){
map[S][j]+=map[T][j];
map[j][S]+=map[j][T];
}
}
}
} int main(){
int u,v,w;
while(scanf("%d%d",&n,&m)!=EOF){
memset(map,,sizeof(map));
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&w);
map[u][v]+=w;
map[v][u]+=w;
// cout<<"YES"<<endl;
}
// cout<<"YES"<<endl;
storewanger();
printf("%d\n",mincut);
}
return ;
}
HDU 3002的更多相关文章
- HDU - 3002 King of Destruction(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=3002 最小割模板 #include<iostream> #include<cmath> ...
- King of Destruction HDU - 3002 && HDU - 3691(全局最小割)
求无向图的最小割 有没有源点都一样,不影响 #include <iostream> #include <cstdio> #include <sstream> #in ...
- poj 2914&&hdu 3002 全局最小割Stoer-Wagner算法模板
#include<stdio.h> #include<string.h> #include<iostream> #define inf 0x3fffffff #de ...
- SW算法求全局最小割(Stoer-Wagner算法)
我找到的唯一能看懂的题解:[ZZ]最小割集Stoer-Wagner算法 似乎是一个冷门算法,连oi-wiki上都没有,不过洛谷上竟然有它的模板题,并且2017百度之星的资格赛还考到了.于是来学习一下. ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- HDU 1075 What Are You Talking About (Trie)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- k-means 聚类前的数据分析
原始数据 Say you are given a data set where each observed example has a set of features, but has nolabel ...
- 8.20noip模拟题
2017-8-20 NOIP模拟赛 by coolyangzc 共3道题目,时间3.5小时 题目名 机器人 数列 虫洞 源文件 robot.cpp/c/pas seq.cpp/c/pas holes. ...
- Python 39 数据库
一:数据存储引擎 1. 什么是引擎? 一个功能的核心部分 引擎可以被分类 例如: 自然 增压 汽油 柴油 混合动力 天然气 核动力 汽油:动力弱,噪音小,震动小 柴油:动力强,污染大,噪音大,震动大 ...
- python修改植物僵尸
import win32process#进程模块 import win32con#系统定义 import win32api#调用系统模块 import ctypes#C语言类型 import win3 ...
- 1.ArcGis几何图形之几何计算
/// <summary> /// 检测几何图形A是否包含几何图形B /// </summary> /// <param name="pGeometryA&qu ...
- Codeforces 609D 被二分教做人
传送门:http://codeforces.com/problemset/problem/609/D (如需转载,请注明出处,谢谢O(∩_∩)O) 题意: Nura想买k个小玩意,她手上有 s 个bu ...
- R - Games
Problem description Manao works on a sports TV. He's spent much time watching the football games of ...
- # --with-http_random_index_module模块
作用: 从目录中随机选取一个随机作为主业 环境 nginx -V 检测是否已经安装了该模块 语法 案例 在/usr/share/nginx下随机创建3个html文件 修改配置文件
- C# 跨平台换行符 System.Environment.NewLine
C# 跨平台换行符 System.Environment.NewLine
- String类面试坑题
1.面试坑题F:\SHJT\JavaWorkspace\JavaSE\workspace\day13ezra\src\cn\itcast\sh\classcode\BTStringLastIndexO ...