转载请注明出处:http://blog.csdn.net/u012860063

题目链接:

pid=4280">http://acm.hdu.edu.cn/showproblem.php?pid=4280

Problem Description
  In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies on the ships.

  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
  The first line contains one integer T (1<=T<=20), the number of test cases.

  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
  For each test case, output an integer in one line, the transport capacity.
 
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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4277 4267 4268 4269 4270 

题意:有N个岛,M条无向路 每一个路有一最大同意的客流量,求从最西的那个岛最多能运用多少乘客到最东的那个岛。

直接上模板:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define PI acos(-1.0)
#define VM 100047
#define EM 400047
int inf = 0x3f3f3f3f;
struct E
{
int to, frm, nxt, cap;
}edge[EM]; int head[VM],e,n,m,src,des;
int dep[VM], gap[VM]; void addedge(int cu, int cv, int cw)
{
edge[e].frm = cu;
edge[e].to = cv;
edge[e].cap = cw;
edge[e].nxt = head[cu];
head[cu] = e++;
edge[e].frm = cv;
edge[e].to = cu;
edge[e].cap = 0;
edge[e].nxt = head[cv];
head[cv] = e++;
} int que[VM]; void BFS()
{
memset(dep, -1, sizeof(dep));
memset(gap, 0, sizeof(gap));
gap[0] = 1;
int front = 0, rear = 0;
dep[des] = 0;
que[rear++] = des;
int u, v;
while (front != rear)
{
u = que[front++];
front = front%VM;
for (int i=head[u]; i!=-1; i=edge[i].nxt)
{
v = edge[i].to;
if (edge[i].cap != 0 || dep[v] != -1)
continue;
que[rear++] = v;
rear = rear % VM;
++gap[dep[v] = dep[u] + 1];
}
}
}
int cur[VM],stack[VM];
int Sap() //sap模板
{
int res = 0;
BFS();
int top = 0;
memcpy(cur, head, sizeof(head));
int u = src, i;
while (dep[src] < n)
{
if (u == des)
{
int temp = inf, inser = n;
for (i=0; i!=top; ++i)
if (temp > edge[stack[i]].cap)
{
temp = edge[stack[i]].cap;
inser = i;
}
for (i=0; i!=top; ++i)
{
edge[stack[i]].cap -= temp;
edge[stack[i]^1].cap += temp;
}
res += temp;
top = inser;
u = edge[stack[top]].frm;
} if (u != des && gap[dep[u] -1] == 0)
break;
for (i = cur[u]; i != -1; i = edge[i].nxt)
if (edge[i].cap != 0 && dep[u] == dep[edge[i].to] + 1)
break; if (i != -1)
{
cur[u] = i;
stack[top++] = i;
u = edge[i].to;
}
else
{
int min = n;
for (i = head[u]; i != -1; i = edge[i].nxt)
{
if (edge[i].cap == 0)
continue;
if (min > dep[edge[i].to])
{
min = dep[edge[i].to];
cur[u] = i;
}
}
--gap[dep[u]];
++gap[dep[u] = min + 1];
if (u != src)
u = edge[stack[--top]].frm;
}
}
return res;
} int main()
{
int T, i;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &m);
int x, y;
int Min = inf, Max = -inf;
for (i=1; i<=n; ++i) //找出起点src 终点des
{
scanf("%d%d", &x, &y);
if (x <= Min)
{
src = i;
Min = x;
}
if (x >= Max)
{
des = i;
Max = x;
}
}
e = 0;
memset(head, -1, sizeof(head));
int u, v, c;
for (i=0; i!=m; ++i)
{
scanf("%d%d%d", &u, &v, &c);
addedge(u,v,c);
addedge(v,u,c);
}
int ans = Sap();
printf("%d\n", ans);
}
return 0;
}

HDU 4280 Island Transport(网络流)的更多相关文章

  1. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  2. HDU 4280 Island Transport

    Island Transport Time Limit: 10000ms Memory Limit: 65536KB This problem will be judged on HDU. Origi ...

  3. Hdu 4280 Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. HDU 4280 Island Transport(无向图最大流)

    HDU 4280:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意: 比较裸的最大流题目,就是这是个无向图,并且比较卡时间. 思路: 是这样的,由于是 ...

  5. HDU 4280 Island Transport(dinic+当前弧优化)

    Island Transport Description In the vast waters far far away, there are many islands. People are liv ...

  6. HDU 4280 Island Transport(HLPP板子)题解

    题意: 求最大流 思路: \(1e5\)条边,偷了一个超长的\(HLPP\)板子.复杂度\(n^2 \sqrt{m}\).但通常在随机情况下并没有isap快. 板子: template<clas ...

  7. G - Island Transport 网络流

    题目: In the vast waters far far away, there are many islands. People are living on the islands, and a ...

  8. 【HDUOJ】4280 Island Transport

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到 ...

  9. Island Transport

    Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...

随机推荐

  1. Oracle Pivot学习心得

    今天在做一个查询报表需要将多行的查询结果转换成一行,数据格式如下 ID   Type Parameter Value Machine_NO Operator UpdateTime 1 11111111 ...

  2. [转]Delphi 中动态链接库(dll)的建立和使用

    动态链接库是一个能够被应用程序和其它的DLL调用的过程和函数的集合体,它里面包含的是公共代码或资源.由于DLL代码使用了内存共享技术,在某些地方windows也给了DLL一些更高的权限,因而DLL中可 ...

  3. DOM中的node与element的区别

    先看document的两个常见method. document.createTextNode Constructor: Text document.createElement Constructor: ...

  4. XML约束图解

  5. 一起学makefile

    Unix.Linux必学知识哈哈,网上看到一哥们写得挺好挺详细的,直接复制地址就分享哈哈哈. 跟我一起写 Makefile(一) 概述 跟我一起写 Makefile(二) make是如何工作的 跟我一 ...

  6. 用Guava辅助Throwable异常处理

    Guava的 Throwables 工具常常可以让exception处理更方便. Propagation 有时候,你会想把捕获的exception抛到上一个try/catch块.对于 RuntimeE ...

  7. head First HTML与CSS读书笔记

    调整图片大小 有滚动条的图片可给不了好的用户体验,为了让图片的大小更适合浏览器窗口.这时候就需要对图片的大小进行调整看书之前.我调整图片大小的方式是在<img>元素使用 width 和 h ...

  8. Hibernate的CRUD

    1.CRUD: C:sesion.save() R:session.get()? session.load() D:session.delete() U:session.update() 2.读取数据 ...

  9. 关于PHPstorm 使用技巧

    慢慢更新,一点点积累,都是自己在使用中遇到的问题 设置:(2016.4.15) 1:注释模板,phpstorm 有非常强大的注释模板,可以根据自己的需求随时更改,并设置快捷键,非常方便 新文件注释 P ...

  10. 网易DBA私享会分享会笔记2

    mysql索引与查询优化什么是索引?索引其实是一个目录.通过各种数据结构实现,是(值=>行位置)的映射 索引的作用:1.提高访问速度2.实现主键.唯一键逻辑 索引使用场景数据量特别大的时候,进行 ...