Gold Transportation

Time Limit: 2000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 3228
64-bit integer IO format: %lld      Java class name: Main

 
Recently, a number of gold mines have been discovered in Zorroming State. To protect this treasure, we must transport this gold to the storehouses as quickly as possible. Suppose that the Zorroming State consists of N towns and there are M bidirectional roads among these towns. The gold mines are only discovered in parts of the towns, while the storehouses are also owned by parts of the towns. The storage of the gold mine and storehouse for each town is finite. The truck drivers in the Zorroming State are famous for their bad temper that they would not like to drive all the time and they need a bar and an inn available in the trip for a good rest. Therefore, your task is to minimize the maximum adjacent distance among all the possible transport routes on the condition that all the gold is safely transported to the storehouses.

 

Input

The input contains several test cases. For each case, the first line is integer N(1<=N<=200). The second line is N integers associated with the storage of the gold mine in every towns .The third line is also N integers associated with the storage of the storehouses in every towns .Next is integer M(0<=M<=(n-1)*n/2).Then M lines follow. Each line is three integers x y and d(1<=x,y<=N,0<d<=10000), means that there is a road between x and y for distance of d. N=0 means end of the input.

 

Output

For each case, output the minimum of the maximum adjacent distance on the condition that all the gold has been transported to the storehouses or "No Solution".

 

Sample Input

4
3 2 0 0
0 0 3 3
6
1 2 4
1 3 10
1 4 12
2 3 6
2 4 8
3 4 5
0

Sample Output

6

Source

 
解题:二分距离。求最小的最大距离。。。
 
源点与宝矿连接,容量为该矿的容量,汇点与藏点连接,容量为藏地的容量。矿 和 藏地的距离进行枚举
 
此题为什么如何建图,我还是有点不明白,奇葩的建图过程。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
};
arc e[maxn*maxn];
int head[maxn],d[maxn],gold[maxn],store[maxn];
int tot,n,m,S,T,cur[maxn],q[maxn],hd,tl;
int a[maxn*maxn],b[maxn*maxn],c[maxn*maxn];
void add(int u,int v,int w) {
e[tot] = arc(v,w,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
void build(int mid) {
memset(head,-,sizeof(head));
tot = ;
for(int i = ; i < m; i++)
if(c[i] <= mid) {
add(a[i],b[i],INF);
add(b[i],a[i],INF);
}
for(int i = ; i <= n; i++)
add(S,i,gold[i]);
for(int i = ; i <= n; i++)
add(i,T,store[i]);
}
bool bfs() {
memset(d,-,sizeof(d));
hd = tl = ;
q[tl++] = S;
d[S] = ;
while(hd < tl) {
int u = q[hd++];
for(int i = head[u]; ~i; i = e[i].next) {
if(d[e[i].to] == - && e[i].flow > ) {
d[e[i].to] = d[u] + ;
q[tl++] = e[i].to;
}
}
}
return d[T] > -;
}
int dfs(int u,int low) {
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow > && d[e[i].to] == d[u] + && (a = dfs(e[i].to,min(low,e[i].flow)))) {
tmp += a;
low -= a;
e[i].flow -= a;
e[i^].flow += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic() {
int tmp = ;
while(bfs()) {
memcpy(cur,head,sizeof(head));
tmp += dfs(S,INF);
}
return tmp;
}
int main() {
int suma,sumb,high,low,ans;
while(scanf("%d",&n),n) {
suma = sumb = ;
for(int i = ; i <= n; i++) {
scanf("%d",gold+i);
suma += gold[i];
}
for(int i = ; i <= n; i++) {
scanf("%d",store+i);
sumb += store[i];
}
scanf("%d",&m);
low = INF;
high = -;
for(int i = ; i < m; i++) {
scanf("%d %d %d",a+i,b+i,c+i);
low = min(low,c[i]);
high = max(high,c[i]);
}
if(suma > sumb) {
puts("No Solution");
continue;
}
ans = -;
S = ;
T = n + ;
while(low <= high) {
int mid = (low + high)>>;
build(mid);
if(dinic() >= suma) {
ans = mid;
high = mid - ;
} else low = mid + ;
}
if(ans > ) printf("%d\n",ans);
else puts("No Solution");
}
return ;
}

POJ 3228 Gold Transportation的更多相关文章

  1. POJ 3228 Gold Transportation(带权并查集,好题)

    参考链接:http://www.cnblogs.com/jiaohuang/archive/2010/11/13/1876418.html 题意:地图上某些点有金子,有些点有房子,还有一些带权路径,问 ...

  2. poj 3228 Gold Transportation 二分+网络流

    题目链接 给出n个城市, 每个城市有一个仓库, 仓库有容量限制, 同时每个城市也有一些货物, 货物必须放到仓库中. 城市之间有路相连, 每条路有长度. 因为有些城市的货物量大于仓库的容量, 所以要运到 ...

  3. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  4. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  5. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  6. POJ:3228-Gold Transportation(要求最小生成树最大边最小)

    Gold Transportation Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3079 Accepted: 1101 D ...

  7. poj 3228(二分+最大流)

    题目链接:http://poj.org/problem?id=3228 思路:增设一个超级源点和一个超级汇点,源点与每一个gold相连,容量为gold数量,汇点与仓库相连,容量为仓库的容量,然后就是二 ...

  8. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

随机推荐

  1. Spring——概览

    Spring是什么? Spring是帮助开发者简化开发工作的工具. Spring的出现就是为了简化人们的复杂的开发.能够在不论什么Java应用中使用,使用了主要的JavaBean取代EJB. Spri ...

  2. DRP——重定向与转发

    重定向 重定向就是又一次进行请求.第一次请求.容器推断请求的类型,是否须要重定向. 重定向的语句是"response.SendRedirect("index.jsp"); ...

  3. POJ2576 Tug of War 二维背包

    题目大意 一群人拔河,给出每个人的重量,要求两队人数之差不超过1人,且每队总重量之差最小. 思路 选出严格总人数一半(或+1)的人为一队,在该队重量不超过所有人总重量一半的情况下,使其重量最大. 人数 ...

  4. spring注入对象类型的属性

    一.1.创建service类和Dao类 (1)在service中得到dao对象 2.具体实现过程 (1)在service里边把dao作为类型属性 (2)生成dao类型属性的set方法 public c ...

  5. Camera-hal参数调整

    路径: vendor/mediatek/proproetary/custom/mt6735/hal/D1/imgsensor/对应的SENSOR目录 .../D1/flashlight/flash_t ...

  6. 国内物联网平台初探(八):中移物联网开放平台OneNet

    平台定位 OneNET是中移物联网有限公司搭建的开放.共赢设备云平台,为各种跨平台物联网应用.行业解决方案,提供简便的云端接入.存储.计算和展现,快速打造物联网产品应用,降低开发成本. IoT Paa ...

  7. 杂项-DB:时序数据库

    ylbtech-杂项-DB:时序数据库 1.返回顶部 1. 时序数据库全称为时间序列数据库.时间序列数据库主要用于指处理带时间标签(按照时间的顺序变化,即时间序列化)的数据,带时间标签的数据也称为时间 ...

  8. java+appium+安卓模拟器实现app自动化Demo

    网上有比较多相关教程,自己写一遍,加深下印象. 环境搭建 据说,很多人都被繁琐的环境搭建给吓到了. 是的,确实,繁琐. node.js 网址 cmd输入node -v,出现下图说明成功. JDK 网址 ...

  9. 从实现HTML页面局部刷新到JSONP

    也可以用iframe方法发get请求,但是目前iframe基本已经被弃用,所以此处就不介绍这个方法. 方案一:用图片造 get 请求 button.addEventListener('click', ...

  10. jQuery中事件模块介绍

    事件模块 1.提供其他DOM方法 包括:next 和 nextAll方法 1.1 next方法实现 目标:扩展框架方法,获取当前元素的下一个元素 问题:如何获取下一个元素? 1.1.1 提供 next ...