HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)
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.
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
#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算法)的更多相关文章
- HDU 3691 Nubulsa Expo(全局最小割)
Problem DescriptionYou may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa i ...
- UVALive 5099 Nubulsa Expo 全局最小割问题
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- HDU 3691 Nubulsa Expo
无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- UVALive 5099 Nubulsa Expo 全球最小割 非网络流量 n^3
主题链接:点击打开链接 意甲冠军: 给定n个点m条无向边 源点S 以下m行给出无向边以及边的容量. 问: 找一个汇点,使得图的最大流最小. 输出最小的流量. 思路: 最大流=最小割. 所以题意就是找全 ...
- 求全局最小割(SW算法)
hdu3002 King of Destruction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 图的全局最小割的Stoer-Wagner算法及例题
Stoer-Wagner算法基本思想:如果能求出图中某两个顶点之间的最小割,更新答案后合并这两个顶点继续求最小割,到最后就得到答案. 算法步骤: --------------------------- ...
- 全局最小割StoerWagner算法详解
前言 StoerWagner算法是一个找出无向图全局最小割的算法,本文需要读者有一定的图论基础. 本文大部分内容与词汇来自参考文献(英文,需***),用兴趣的可以去读一下文献. 概念 无向图的割:有无 ...
- poj 2914(stoer_wanger算法求全局最小割)
题目链接:http://poj.org/problem?id=2914 思路:算法基于这样一个定理:对于任意s, t V ∈ ,全局最小割或者等于原图的s-t 最小割,或者等于将原图进行 Cont ...
- poj2914 Minimum Cut 全局最小割模板题
Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 8324 Accepted: 3488 Case ...
随机推荐
- Windows下mysql自动备份的最佳方案
网上有很多关于window下Mysql自动备份的方法,其实不乏一些不好的地方和问题,现总结出一个最好的方法供大家参考: 新建一个记事本,然后重命名为: mysql_backup.bat 然后单击右键选 ...
- JavaScript函数参数与调用
函数调用: /* 1. 函数调用 */ ,,,); /* 2. 方法调用 */ this.CName = "全局"; var o = { CName:"o类", ...
- LMAO?
70 weeks to finish TC problems? 2015.4.16 week1 week1~week8:Graph 1.DFS,BFS,Topological sort,Strongl ...
- iOS新建项目文件管理规范
当我们进入到新的公司的第一天,看到以前老员工编写的代码,找个东西累死人咧,那个抓耳挠腮的啊,一般情况下都有想揍人的赶脚. 哈哈,不忙,先想一下自己的代码!想一下自己写的代码怎么才能新来的人一眼就能看懂 ...
- freebsd 禁用root登录ssh并给普通用户登录权限
转自http://www.linux521.com/2009/system/200904/2021.html http://www.myhack58.com/Article/48/67/2011/30 ...
- Mixing Delphi and C++(相互调用)
Mixing Delphi and C++ You have a TStringList and <algorithm>. What can you do? Quite a lot, ac ...
- 单个未知大小图片在div里面垂直居中的方法。。。添加辅助元素挤一下位置达到居中
单个未知大小图片在div里面垂直居中的方法...添加辅助元素挤一下位置达到居中 <div class="ServicesLiTopPic"> <i>&l ...
- 链表之求链表倒数第k个节点
题目描述:输入一个单向链表,输出该链表中倒数第k个节点,链表的倒数第0个节点为链表的尾指针. 最普遍的方法是,先统计单链表中结点的个数,然后再找到第(n-k)个结点.注意链表为空,k为0,k为1,k大 ...
- 通过SessionID和用户名来保证同一个用户不能同时登录(单点登录)
可以通过SessionID和用户名来保证同一个用户不能同时登录的问题,下面程序模仿了QQ的登录,当登录后判断当前帐号是否已经登录,如果登录.则踢掉以前登录的用户. 1.通过Application全局变 ...
- iPhone批量删除照片/视频最好用的方法
iPhone批量删除照片/视频最好用的方法 经过大量的搜索和不懈的尝试,今天终于找到了批量删除iPhone照片最好用的方法, 于是决定写一篇博客为更多的果粉们造福! 1. 通过USB将iPhone手机 ...