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 ...
随机推荐
- [bzoj] 3673 3674 可持久化并查集 || 可持久化数组
原题 加强版 题意: 可持久化并查集模板-- 题解: 用可持久化线段树维护一个可持久化数组,来记录每一次操作后的状态. 不能用路径压缩,但是要按置合并,使复杂度保证在O(log) #include&l ...
- idea导入web项目tomcat
概述 主要分为项目配置和tomcat配置两大步骤. 一.项目配置 打开idea,选择导入项 选择将要打开的项目路径后,继续选择项目的原本类型(后续引导设置会根据原本的项目类型更新成idea的项目),此 ...
- STL之四:list用法详解
转载于:http://blog.csdn.net/longshengguoji/article/details/8520891 list容器介绍 相对于vector容器的连续线性空间,list是一个双 ...
- DOM基本代码一
dom学习基本代码第一部分 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...
- HDU1260DP
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- 顺序统计:寻找序列中第k小的数
最直观的解法,排序之后取下标为k的值即可. 但是此处采取的方法为类似快速排序分块的方法,利用一个支点将序列分为两个子序列(支点左边的值小于支点的值,支点右边大于等于支点的值). 如果支点下标等于k,则 ...
- 洛谷P2860 [USACO06JAN]冗余路径Redundant Paths
题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1. ...
- NGINX: 反向代理 Nexus
Nginx 反向代理 nexus 的服务, 一直卡在 Initialize... 解决方式是添加一个 header X-Forwarded-Proto: proxy_set_header X-Forw ...
- NightMare2(SCU4527+dijkstra+二分)
题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4527 题目: 题意:最短路的每条边除了边权之外还会有一个限制(财富,身上带的财富大于这个值则不能通 ...
- 如何免费上传4G以上大文件至百度云网盘
百度云网盘的容量高达2048G,因而如今使用百度云网盘的用户也越来越多, 但是百度云中如果要上传超过4G的大文件,必须要升级VIP才行,但这需要收费.那么,超过4G以上的大文件我们该怎样上传到百度云呢 ...