UVALive 5099
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 <string.h>
#include <cmath>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = ;
const ll maxw = ;
const ll inf = 1e17;
ll g[N][N], w[N];
int a[N], v[N], na[N];
ll mincut(int n) {
int i, j, pv, zj;
ll best = inf;
for(i = ; i < n; i ++) {
v[i] = i;
}
while(n > ) {
for(a[v[]] = , i = ; i < n; i ++) {
a[v[i]] = ;
na[i - ] = i;
w[i] = g[v[]][v[i]];
}
for(pv = v[], i = ; i < n; i ++) {
for(zj = -, j = ; j < n; j ++)
if(!a[v[j]] && (zj < || w[j] > w[zj])) {
zj = j;
}
a[v[zj]] = ;
if(i == n - ) {
if(best > w[zj]) {
best = w[zj];
}
for(i = ; i < n; i ++) {
g[v[i]][pv] = g[pv][v[i]] += g[v[zj]][v[i]];
}
v[zj] = v[--n];
break;
}
pv = v[zj];
for(j = ; j < n; j ++) if(!a[v[j]]) {
w[j] += g[v[zj]][v[j]];
}
}
}
return best;
}
int main()
{
int n, m, s;
while(~scanf("%d %d", &n, &m))
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
g[i][j] = ;
}
}
int u, v, w;
for(int i = ; i < m; i++)
{
scanf("%d %d %d", &u, &v, &w);
u--;
v--;
g[u][v] += w;
g[v][u] += w;
}
printf("%lld\n", mincut(n));
}
return ;
}
UVALive 5099的更多相关文章
- UVALive 5099 Nubulsa Expo 全局最小割问题
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVALive 5099 Nubulsa Expo 全球最小割 非网络流量 n^3
主题链接:点击打开链接 意甲冠军: 给定n个点m条无向边 源点S 以下m行给出无向边以及边的容量. 问: 找一个汇点,使得图的最大流最小. 输出最小的流量. 思路: 最大流=最小割. 所以题意就是找全 ...
- UVALive 5099 Nubulsa Expo(全局最小割)
题面 vjudge传送门 题解 论文题 见2016绍兴一中王文涛国家队候选队员论文<浅谈无向图最小割问题的一些算法及应用>4节 全局最小割 板题 CODE 暴力O(n3)O(n^3)O(n ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
随机推荐
- BZOJ2434 [Noi2011]阿狸的打字机 【AC自动机 + fail树 + 树状数组】
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 3610 Solved: 1960 [Submit][S ...
- bzoj3680: 吊打XXX(模拟退火)
题目要求 最小(dis表示绳结到点i的距离),就是个广义费马点的题,模拟退火裸题QAQ 模拟退火就是优化后的爬山算法,一开始先随机一个平均点,接下来如果随机到的点比当前点劣,温度比较高的话也有几率跳过 ...
- mysql主从同步加读写分离
首先主从同步,一旦建立,指定了用户,就不能更改了,否则会有错误.1063 Error 'Duplicate entry '%-test-' for key 'PRIMARY'' on query. D ...
- 关于JavaScript的push()函数
push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度.返回值为把指定的值添加到数组后的新长度. 语法:arrayObject.push(newelement1,newelement2,. ...
- VS 2013 with update安装失败(kb2829760)解决方案
update过程中遇到kb2829760补丁无法更新而导致vs安装失败的解决方法: 1.安装KB2829760: 2.安装KB2829760中文语言包: 3.安装VS2013 with update. ...
- ACE线程管理机制-并发控制(2)
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/04/581793.html ACE Guard类属 与C一级的互斥体API相比较,Mutex包 ...
- 题解【poj2774 Long Long Message】
Description 求两个串的最长连续公共字串 Solution 后缀数组入门题吧 把两个串连在一起,中间加一个分隔符,然后跑一遍后缀数组,得到 height 和 sa 一个 height[i] ...
- ACM2647拓扑排序逆运算
2647题是对工人排序问题,不是从头到尾排序,而是从尾到头排序: 代码中用到vector和queue容器,权当练习. 用广搜进行拓扑排序的逆运算. #include<iostream> # ...
- Moodle简介
Moodle简介 一.概述 Moodle是Modular Object-Oriented Dynamic Learning Environment(模块化面向对象动态学习环境)的简称,中文译名为魔灯, ...
- 【模版】多项式乘法 FFT
https://www.luogu.org/problem/show?pid=3803 题目背景 这是一道模版题 题目描述 给定一个n次多项式F(x),和一个m次多项式G(x). 请求出F(x)和G( ...