HDU 4280 Island Transport
Island Transport
This problem will be judged on HDU. Original ID: 4280
64-bit integer IO format: %I64d Java class name: Main
You have a
transportation company there. Some routes are opened for passengers.
Each route is a straight line connecting two different islands, and it
is bidirectional. Within an hour, a route can transport a certain number
of passengers in one direction. For safety, no two routes are cross or
overlap and no routes will pass an island except the departing island
and the arriving island. Each island can be treated as a point on the XY
plane coordinate system. X coordinate increase from west to east, and Y
coordinate increase from south to north.
The transport capacity is
important to you. Suppose many passengers depart from the westernmost
island and would like to arrive at the easternmost island, the maximum
number of passengers arrive at the latter within every hour is the
transport capacity. Please calculate it.
Input
Then T test cases follow. The first line of each test case contains two
integers N and M (2<=N,M<=100000), the number of islands and the
number of routes. Islands are number from 1 to N.
Then N lines
follow. Each line contain two integers, the X and Y coordinate of an
island. The K-th line in the N lines describes the island K. The
absolute values of all the coordinates are no more than 100000.
Then M lines follow. Each line contains three integers I1, I2
(1<=I1,I2<=N) and C (1<=C<=10000) . It means there is a
route connecting island I1 and island I2, and it can transport C
passengers in one direction within an hour.
It is guaranteed that
the routes obey the rules described above. There is only one island is
westernmost and only one island is easternmost. No two islands would
have the same coordinates. Each island can go to any other island by the
routes.
Output
Sample Input
2
5 7
3 3
3 0
3 1
0 0
4 5
1 3 3
2 3 4
2 4 3
1 5 6
4 5 3
1 4 4
3 4 2
6 7
-1 -1
0 1
0 2
1 0
1 1
2 3
1 2 1
2 3 6
4 5 5
5 6 3
1 4 6
2 5 5
3 6 4
Sample Output
9
6
Source
#include <bits/stdc++.h>
using namespace std;
const int INF = ~0U>>;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
}e[];
int head[maxn],d[maxn],gap[maxn],tot,S,T,n,m;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,flow,head[v]);
head[v] = tot++;
}
queue<int>q;
void bfs(){
for(int i = ; i <= n; ++i){
d[i] = -;
gap[i] = ;
}
d[T] = ;
q.push(T);
while(!q.empty()){
int u = q.front();
q.pop();
++gap[d[u]];
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,minH = n - ;
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow){
if(d[e[i].to] + == d[u]){
int a = dfs(e[i].to,min(low,e[i].flow));
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!low) break;
if(d[S] >= n) return tmp;
}
if(e[i].flow) minH = min(minH,d[e[i].to]);
}
}
if(!tmp){
if(--gap[d[u]] == ) d[S] = n;
++gap[d[u] = minH + ];
}
return tmp;
}
int main(){
int kase,x,y,s,t,u,v,w;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&m);
memset(head,-,sizeof head);
s = INF;
int ret = t = ;
for(int i = ; i <= n; ++i){
scanf("%d%d",&x,&y);
if(s > x){
s = x;
S = i;
}
if(t < x){
t = x;
T = i;
}
}
for(int i = tot = ; i < m; ++i){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
}
bfs();
while(d[S] < n) ret += dfs(S,INF);
printf("%d\n",ret);
}
return ;
}
HDU 4280 Island Transport的更多相关文章
- HDU 4280 Island Transport(网络流,最大流)
HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...
- Hdu 4280 Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 4280 Island Transport(无向图最大流)
HDU 4280:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意: 比较裸的最大流题目,就是这是个无向图,并且比较卡时间. 思路: 是这样的,由于是 ...
- HDU 4280 Island Transport(dinic+当前弧优化)
Island Transport Description In the vast waters far far away, there are many islands. People are liv ...
- HDU 4280 Island Transport(网络流)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...
- HDU 4280 Island Transport(HLPP板子)题解
题意: 求最大流 思路: \(1e5\)条边,偷了一个超长的\(HLPP\)板子.复杂度\(n^2 \sqrt{m}\).但通常在随机情况下并没有isap快. 板子: template<clas ...
- 【HDUOJ】4280 Island Transport
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到 ...
- Island Transport
Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...
- HDU4280:Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
随机推荐
- matlab各向异性扩散滤波
主要是用来平滑图像的,克服了高斯模糊的缺陷,各向异性扩散在平滑图像时是保留图像边缘的(和双边滤波很像). 通常我们有将图像看作矩阵的,看作图的,看作随机过程的,记得过去还有看作力场的. 这次新鲜,将图 ...
- DrawTool画笔之纹理笔
先上图: 今天我们要实现的是DrawTool画笔集合中的一种纹理笔,很多人可能对纹理笔概念还比较生疏,其实如果你接触过类似一些教育行业交互式白板的话,对纹理笔并不会感到陌生,纹理笔我们可以简单的理解为 ...
- Java语言中自动生成随机数
参考原文:http://zhidao.baidu.com/link?url=nB3BT69wmUAiSPfKGgK5Q7HOFFP9AIE04AthreRd9yYcwKhUQsQRWlMdMhW1Qm ...
- 怎样将python的文件转化为windows的可执行程序
最近我在刚入手python,其中就学到了怎样将python的py格式文件转化为windows的exe执行程序, 是这样的,首先要创建一个py文件,这里给截图吧 接下来就以这个python文件为例创建一 ...
- IE6常见CSS解析Bug和hack
第一:图片间隙 a:div中的图片间隙: 描述:在div中插入图片时,图片会将div下方撑大3像素 hack1:将<div>和<img>写在一行 hack2:将<img& ...
- java 删除字符串最后一个字符的几种方法
偶然看到的,记录一下,以免忘记 字符串:string s = "1,2,3,4,5," 目标:删除最后一个 "," 方法: 1.用的最多的是Substri ...
- mysql IF语句使用
类似于三元运算符 1) IF(where,result1,result2) = where?result1:result2 例如 SELECT IF(1=1,1,2) => 1 2) ...
- Fedora19添加和设置YUM源
Fedora19添加和设置YUM源添加yum源前先安装fastestmirror/downloadonly插件和axelget插件: 1.安装fastestmirror/downloadonly插件 ...
- faster rcnn细节总结
1.roi_pooling层是先利用spatial_scale将region proposal映射到feature map上,然后利用pooled_w.pooled_h分别将映射后的框的长度.宽度等分 ...
- 实现类似add(1)(2)(3)的函数
要求实现类似add(1)(2)(3)调用方式的方法,例如add为加法函数,则调用add(1)(2)输出3,调用add(1)(5)(3)输出9. 函数的调用方式是多次调用同一个函数,将每次传入的参数 ...