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 < 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.
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 ...
随机推荐
- BZOJ4573:[ZJOI2016]大森林——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4573 https://www.luogu.org/problemnew/show/P3348#sub ...
- [Leetcode] search in rotated sorted array ii 搜索旋转有序数组
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- git生成ssh key和多账号支持
git配置ssh 1.首先设置git的全局user name和email $ git config --global user.name "ygtzz"$ git config - ...
- 2016多校联合训练1 B题Chess (博弈论 SG函数)
题目大意:一个n(n<=1000)行,20列的棋盘上有一些棋子,两个人下棋,每回合可以把任意一个棋子向右移动到这一行的离这个棋子最近的空格上(注意这里不一定是移动最后一个棋子),不能移动到棋盘外 ...
- [NOI2017]蔬菜——时光倒流+贪心
题目链接 题解: 貌似一眼看过去是一个贪心. 其他的算法要记录的东西就太多了. 部分分其实很高.但是没有什么提示. 想一些套路:二分?不行还要贪心判断. 分治?前后取法是有影响的. 时光倒流? 也许可 ...
- java 面向对象编程(OOP)
java是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开发的优点: 代码开发模块化,更易维护和修改: 代码复用: 增加代码的可靠性和灵活性: 增加代码的可理解性. 封装 封装 ...
- [Leetcode] LRU 算法实现
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- ListView - SimpleAdapter 行间颜色交替(转)
一.概述 通过扩展SimpleAdapter,来改变显示外观.因为要每行的显示颜色,首先要获得每行的View实例,然后调用setBackgroundColor函数设置. 二.实例 [效果] [代码片段 ...
- Spring 与 Quartz 动态配置(数漫江湖)
因为项目的需求,需要有动态配置计划任务的功能.本文在 Quartz JobBean 中获取配置的 Quartz cronExpression 时间表达式及 Spring Bean 的对象名.方法名并运 ...
- Codeforces Round #478 (Div. 2)
题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...