最小割Stoer-Wagner算法模板hdu3691
来源:互联网 发布:被一个人爱的感觉知乎 编辑:程序博客网 时间:2024/06/01 10:44
#include <stdio.h>#include <string.h>#include <iostream>#include <cctype>#include <string>#include <cmath>#include <algorithm>#include <queue>#include <set>#include <vector>#include <map>#define PR pair<int,int>#define MP make_pair#define fi first#define se second#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define sqr(x) ((x)*(x))#define ll __int64const int M=21000;const int N=350;const int MOD=1000000007;const int INF=0x3f3f3f3f;const double eps=1e-10;const double pi=3.1415926536;using namespace std;int n,m,S,T;int mincut;int vis[N];int wet[N];int combine[N];int mp[N][N];void Search(){ int i,j,mx,tmp; memset(vis,0,sizeof(vis)); memset(wet,0,sizeof(wet)); S=T=-1; for(i=0;i<n;i++) { mx=-INF; for(j=0;j<n;j++) { if(!combine[j]&&!vis[j]&&wet[j]>mx) { tmp=j; mx=wet[j]; } } if(T==tmp) return; S=T;T=tmp; mincut=mx; vis[tmp]=1; for(j=0;j<n;j++) { if(!combine[j]&&!vis[j]) wet[j]+=mp[tmp][j]; } }}int SW(){ int i,j; memset(combine,0,sizeof(combine)); int ans=INF; for(i=0;i<n-1;i++) { Search(); ans=min(ans,mincut); if(ans==0) return 0; combine[T]=1; for(j=0;j<n;j++) { if(!combine[j]) { mp[S][j]+=mp[T][j]; mp[j][S]+=mp[j][T]; } } } return ans;}int main(){ //freopen("in.txt","r",stdin); while(~scanf("%d%d%d",&n,&m,&S)&&n&&m&&S) { memset(mp,0,sizeof(mp)); for(int i=0;i<m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); u--;v--; mp[u][v]+=w; mp[v][u]+=w; } printf("%d\n",SW()); }}
0 0
- 最小割Stoer-Wagner算法模板hdu3691
- 【最小割】Stoer-Wagner模板
- 最小割 Stoer-Wagner 算法
- Stoer-Wagner算法(O(n^3))求全局最小割 hdu3691 2010福州站B题
- 最小割集Stoer-Wagner算法【ZZ】
- 最小割集Stoer-Wagner算法
- 最小割集Stoer-Wagner算法
- 最小割集Stoer-Wagner算法
- 最小割集Stoer-Wagner算法
- Stoer-Wagner算法求全局最小割
- poj 2914 最小割 Stoer-Wagner 算法
- 全局最小割集Stoer-Wagner算法
- Stoer-Wagner算法(最小割集)
- poj 2914 全局最小割 stoer wagner算法 最小割模板
- poj 2914&&hdu 3002 全局最小割Stoer-Wagner算法模板
- poj 2914 Minimum Cut 求无向图的最小割 Stoer-Wagner算法模板
- POJ2914 Minimum Cut 【全局最小割Stoer-Wagner模板题】
- 最小割集Stoer-Wagner算法,网络最大流问题
- TCP零窗口更新与超时重传联合优化的packetdrill确认
- POJ 3237 Tree 树链剖分
- 标准模板库STL学习总结
- HDU 1272 小希的迷宫(带环并查集)
- sqoop-1.99.3安装
- 最小割Stoer-Wagner算法模板hdu3691
- hdu 1043 eight (搜索 + 康托展开)
- hdu2612 Find a way--BFS & 打表
- 2015 Multi-University Training Contest 3
- 游戏机器人
- android搭建开发环境
- 关于Linux 下的错误路由产生火星包的问题
- 格式化时间
- C#的第7节课