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 ...
随机推荐
- js 跨浏览器实现事件
我们知道不同的浏览器实现事件是不同的,就比如说我们常见的有三种方法: 1,dom0处理事件的方法,以前的js处理事件都是这样写的. (function () { var p=document.getE ...
- Aop第一节
什么是AOP AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善.OOP引入 ...
- MySql中查询语句实现分页功能
import java.util.*;import java.sql.*; public class FruitDao { private Connection conn; private ...
- react注意点
event 对象 和普通浏览器一样,事件监听函数会被自动传入一个 event 对象,这个对象和普通的浏览器 event 对象所包含的方法和属性都基本一致.不同的是 React.js 中的 event ...
- 洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
贪婪的送礼者Greedy Gift Givers 难度:☆ Code: #include <iostream> #include <cstdio> #include <c ...
- WebService学习之旅(四)Apache Axis2的安装
一.Axis2简介 Axis2是目前使用较多的WebService引擎,它是Axis1.x的升级版本,不仅支持SOAP1.1和SOAP1.2,而且也提供了对REST风格WebService的支持. A ...
- path与classpath区别(转)
转自http://blog.csdn.net/mydreamongo/article/details/8155408 1.path的作用 path是系统用来指定可执行文件的完整路径,即使不在path中 ...
- Nginx常用命令介绍
#安装nginx准备工作yum install gcyum -y install pcre-develyum install -y zlib-devel #编译安装./configuremake &a ...
- 查询sqlserver数据库,表占用数据大小
if exists(select 1 from tempdb..sysobjects where id=object_id('tempdb..#tabName') and xtype='u')dro ...
- codevs 2728 整数帝国问题(水题日常)
时间限制: 1 s 空间限制: 16000 KB 题目等级 : 白银 Silver 题目描述 Description 在很久以前,在遥远的东方,有一个整数帝国,它里面里居住着大量的正整数,了缓解都 ...