Problem Description
You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa is an undeveloped country and it is threatened by the rising of sea level. Scientists predict that Nubulsa will disappear by the year of 2012. Nubulsa government wants to host the 2011 Expo in their country so that even in the future, all the people in the world will remember that there was a country named “Nubulsa”.

As you know, the Expo garden is made up of many museums of different countries. In the Expo garden, there are a lot of bi-directional roads connecting those museums, and all museums are directly or indirectly connected with others. Each road has a tourist capacity which means the maximum number of people who can pass the road per second.

Because Nubulsa is not a rich country and the ticket checking machine is very expensive, the government decides that there must be only one entrance and one exit. The president has already chosen a museum as the entrance of the whole Expo garden, and it’s the Expo chief directory Wuzula’s job to choose a museum as the exit.

Wuzula has been to the Shanghai Expo, and he was frightened by the tremendous “people mountain people sea” there. He wants to control the number of people in his Expo garden. So Wuzula wants to find a suitable museum as the exit so that the “max tourists flow” of the Expo garden is the minimum. If the “max tourist flow” is W, it means that when the Expo garden comes to “stable status”, the number of tourists who enter the entrance per second is at most W. When the Expo garden is in “stable status”, it means that the number of people in the Expo garden remains unchanged.

Because there are only some posters in every museum, so Wuzula assume that all tourists just keep walking and even when they come to a museum, they just walk through, never stay.

 
Input
There are several test cases, and the input ends with a line of “0 0 0”.
For each test case:
The first line contains three integers N, M and S, representing the number of the museums, the number of roads and the No. of the museum which is chosen as the entrance (all museums are numbered from 1 to N). For example, 5 5 1 means that there are 5 museums and 5 roads connecting them, and the No. 1 museum is the entrance.
The next M lines describe the roads. Each line contains three integers X, Y and K, representing the road connects museum X with museum Y directly and its tourist capacity is K.
Please note:
1<N<=300, 0<M<=50000, 0<S,X,Y<=N, 0<K<=1000000
 
Output
For each test case, print a line with only an integer W, representing the “max tourist flow” of the Expo garden if Wuzula makes the right choice.
 
题目大意:给一个无向连通图,给定一个起点,你可以任意确定一个终点,使得这两个点之间的最大流最大,求这个最大流。
思路:由最大流最小割定理,而又因为不管最小割长什么样,起点必然在一个集合,只要随意在另一个集合找一个终点,即可得到所求最大流。题目转化为求全局的最小割,采用Stoer-Wagner算法,复杂度为(O(n^3))。
全局最小割StoerWagner算法详解:http://www.cnblogs.com/oyking/p/7339153.html
 
代码(1765MS):
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL; const int MAXN = ; LL mat[MAXN][MAXN];
LL weight[MAXN];
bool del[MAXN], vis[MAXN];;
int n, m, st; void init() {
memset(mat, , sizeof(mat));
memset(del, , sizeof(del));
} LL StoerWagner(int &s, int &t, int cnt) {
memset(weight, , sizeof(weight));
memset(vis, , sizeof(vis));
for(int i = ; i <= n; ++i)
if(!del[i]) {t = i; break; }
while(--cnt) {
vis[s = t] = true;
for(int i = ; i <= n; ++i) if(!del[i] && !vis[i]) {
weight[i] += mat[s][i];
}
t = ;
for(int i = ; i <= n; ++i) if(!del[i] && !vis[i]) {
if(weight[i] >= weight[t]) t = i;
}
}
return weight[t];
} void merge(int s, int t) {
for(int i = ; i <= n; ++i) {
mat[s][i] += mat[t][i];
mat[i][s] += mat[i][t];
}
del[t] = true;
} LL solve() {
LL ret = -;
int s, t;
for(int i = n; i > ; --i) {
if(ret == -) ret = StoerWagner(s, t, i);
else ret = min(ret, StoerWagner(s, t, i));
merge(s, t);
}
return ret;
} int main() {
while(scanf("%d%d%d", &n, &m, &st) != EOF) {
if(n == && m == && st == ) break;
init();
while(m--) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
mat[x][y] += z;
mat[y][x] += z;
}
cout<<solve()<<endl;
}
}

HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)的更多相关文章

  1. HDU 3691 Nubulsa Expo(全局最小割)

    Problem DescriptionYou may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa i ...

  2. UVALive 5099 Nubulsa Expo 全局最小割问题

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  3. HDU 3691 Nubulsa Expo

    无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  4. UVALive 5099 Nubulsa Expo 全球最小割 非网络流量 n^3

    主题链接:点击打开链接 意甲冠军: 给定n个点m条无向边 源点S 以下m行给出无向边以及边的容量. 问: 找一个汇点,使得图的最大流最小. 输出最小的流量. 思路: 最大流=最小割. 所以题意就是找全 ...

  5. 求全局最小割(SW算法)

    hdu3002 King of Destruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  6. 图的全局最小割的Stoer-Wagner算法及例题

    Stoer-Wagner算法基本思想:如果能求出图中某两个顶点之间的最小割,更新答案后合并这两个顶点继续求最小割,到最后就得到答案. 算法步骤: --------------------------- ...

  7. 全局最小割StoerWagner算法详解

    前言 StoerWagner算法是一个找出无向图全局最小割的算法,本文需要读者有一定的图论基础. 本文大部分内容与词汇来自参考文献(英文,需***),用兴趣的可以去读一下文献. 概念 无向图的割:有无 ...

  8. poj 2914(stoer_wanger算法求全局最小割)

    题目链接:http://poj.org/problem?id=2914 思路:算法基于这样一个定理:对于任意s, t   V ∈ ,全局最小割或者等于原图的s-t 最小割,或者等于将原图进行 Cont ...

  9. poj2914 Minimum Cut 全局最小割模板题

    Minimum Cut Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 8324   Accepted: 3488 Case ...

随机推荐

  1. sql 语句查询练习题

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student 2. 查询教师所有的单位即不重复的Depart列 ...

  2. 【C51】单片机独立按键与矩阵按键

    独立按键 首先既然是检测输入,对于当然要用到拉电阻,来检测引脚电平变化变化.51单片机中,除了P0口外,P2,P3,P4都是内置上拉电阻的准双向IO口,一般 的 51 P0引脚都外接了上拉电阻,当然也 ...

  3. 【Android开发学习笔记】【第八课】五大布局-下

    概念 五大布局上一篇文章已经介绍了 LinearLayout RelativeLayout 这一篇我们介绍剩下的三种布局 FrameLayout 五种布局中最佳单的一种布局.在这个布局在整个界面被当成 ...

  4. 一切从IL开始

    IL是什么? IL是Intermediate Language的缩写,是.Net代码转化成机器语言的一个中间语言,因此又把IL语言称之为反汇编语言. IL工具有哪些? 俗话说,工欲善其事必先利其器.了 ...

  5. iOS视图控制对象生命周期

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  6. 修改Wordpress目录

    安装完wordpress,此时访问地址为:http://localhost/wordpress 1.不想让人知道我的文件目录,于是我把原来的wordpress改为w, 2.后台设置 3.WordPre ...

  7. 【转】Android的材料设计兼容库(Design Support Library)

    转自:http://www.jcodecraeer.com/a/anzhuokaifa/developer/2015/0531/2958.html?mType=Group Android的材料设计兼容 ...

  8. 导入maven工程并配置maven环境

    步骤一 : 选择 "Import"操作 有两个途径可以选择 "Import"操作; 1>"File"--> "Impo ...

  9. oracle语句随笔

    oracle语句随笔 dmp数据的导入. ; --创建用户 GRANT CONNECT,RESOURCE,DBA TO memsspc; --赋值权限 --cmd 中导入命令 IMP memsspc@ ...

  10. iOS UIApplicationDelegate

    1.- (void)applicationWillResignActive:(UIApplication *)application说明:当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息或 ...