B - Nubulsa Expo

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

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 < N300,
0 < M50000,
0 < S, X, YN,
0 < K1000000

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.

Sample Input

5 5 1
1 2 5
2 4 6
1 3 7
3 4 3
5 1 10
0 0 0

Sample Output

8
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 555
#define inf 1<<30 int v[MAXN],dist[MAXN];
int map[MAXN][MAXN];
bool vis[MAXN];
int n,m; //求全局最小割的Stoer_Wanger算法
int Stoer_Wanger(int n)
{
int res=inf;
for(int i=;i<n;i++)v[i]=i;
while(n>){
int k=,pre=;//pre用来表示之前加入A集合的点,我们每次都以0点为第一个加入A集合的点
memset(vis,false,sizeof(vis));
memset(dist,,sizeof(dist));
for(int i=;i<n;i++){
k=-;
for(int j=;j<n;j++){
if(!vis[v[j]]){
dist[v[j]]+=map[v[pre]][v[j]];//dis数组用来表示该点与A集合中所有点之间的边的长度之和
if(k==-||dist[v[k]]<dist[v[j]]){
k=j;
}
}
}
vis[v[k]]=true;
if(i==n-){
res=min(res,dist[v[k]]);
//将该点合并到pre上,相应的边权就要合并
for(int j=;j<n;j++){
map[v[pre]][v[j]]+=map[v[j]][v[k]];
map[v[j]][v[pre]]+=map[v[j]][v[k]];
}
v[k]=v[--n];//删除最后一个点
}
pre=k;
}
}
return res;
} int main()
{
int u,v,w,ss;
while(~scanf("%d%d",&n,&m)){ memset(map,,sizeof(map));
while(m--){
scanf("%d%d%d",&u,&v,&w);
u--,v--;
map[u][v]+=w;
map[v][u]+=w;
}
int ans=Stoer_Wanger(n);
printf("%d\n",ans);
}
return ;
}
												

UVALive 5099 Nubulsa Expo 全局最小割问题的更多相关文章

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

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

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

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

  3. UVALive 5099 Nubulsa Expo(全局最小割)

    题面 vjudge传送门 题解 论文题 见2016绍兴一中王文涛国家队候选队员论文<浅谈无向图最小割问题的一些算法及应用>4节 全局最小割 板题 CODE 暴力O(n3)O(n^3)O(n ...

  4. HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)

    Problem Description You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa ...

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

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

  6. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  7. 全局最小割Stoer-Wagner算法

    借鉴:http://blog.kongfy.com/2015/02/kargermincut/ 提到无向图的最小割问题,首先想到的就是Ford-Fulkerson算法解s-t最小割,通过Edmonds ...

  8. HDU 6081 度度熊的王国战略(全局最小割堆优化)

    Problem Description度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族.哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士.所以这一场战争,将会十分艰难.为了更好的进攻 ...

  9. HDU 6081 度度熊的王国战略(全局最小割Stoer-Wagner算法)

    Problem Description 度度熊国王率领着喵哈哈族的勇士,准备进攻哗啦啦族. 哗啦啦族是一个强悍的民族,里面有充满智慧的谋士,拥有无穷力量的战士. 所以这一场战争,将会十分艰难. 为了更 ...

随机推荐

  1. 一个SAP顾问在美国的这些年

    今天的文章来自我的老乡宋浩,之前作为SAP顾问在美国工作多年.如今即将加入SAP成都研究院S4CRM开发团队.我们都是大邑人. 大邑县隶属于四川省成都市,位于成都平原西部,与邛崃山脉接壤.东与崇州市交 ...

  2. idea单元测试junit

    参考文章地址地址:http://blog.csdn.net/u011138533/article/details/52165577 本文按以下顺序讲解JUnit4的使用 下载jar包 单元测试初体验 ...

  3. 简析平衡树(一)——替罪羊树 Scapegoat Tree

    前言 平衡树在我的心目中,一直都是一个很高深莫测的数据结构.不过,由于最近做的题目的题解中经常出现"平衡树"这三个字,我决定从最简单的替罪羊树开始,好好学习平衡树. 简介 替罪羊树 ...

  4. ifup/ifdown ethX 和 ifconfig ehtX up/down的区别

    相同点:[启用]和[禁止]网卡 ifup  ethX 和 ifconfig  ethX  up               用来启用网卡设备 ifdown  ethX 和 ifconfig  ethX ...

  5. css布局:块级元素的居中

    一.定宽: 1.定位居中(absolute) 方法一: html: <div class="main"></main> css: .main{ width: ...

  6. ios 导航视图控制器 跳转

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  7. Mint UI文档

    Mint UI文档:http://elemefe.github.io/mint-ui/#/ 一.Mint UI的安装和基本用法. 1.NPM :npm i mint-ui -S 建议使用npm进行安装 ...

  8. Uva 填充正方形

    暴力出奇迹 #include<iostream> #include<cstdio> using namespace std; +; int T,n; char S[maxn][ ...

  9. Nosql和RDBMS的比较及解释

    概述 传统的关系型数据库以及数据仓库在面对大数据的处理时显得越来越力不从心.因为关系数据库管理系统 (RDBMS)的设计从未考虑过能够处理日益增长且格式多变的数据,以及访问数据并进行分析的用户需求呈爆 ...

  10. 使用JFreeChart生成报表

    1.JFreeChart简介    JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications,servlets以及JSP等使用所设计.  ...