题目链接:https://vjudge.net/problem/HDU-4280

Island Transport

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 9945    Accepted Submission(s): 3214

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

题解:

最大流的裸题,不过对时间效率要求较高。所以就用了ISAP。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXN = 1e5+; struct Edge
{
int to, next, cap, flow;
}edge[MAXN<<];
int tot, head[MAXN]; int gap[MAXN], dep[MAXN], cur[MAXN]; void init()
{
tot = ;
memset(head, -, sizeof(head));
} void add(int u, int v, int w)
{
edge[tot].to = v; edge[tot].cap = w; edge[tot].flow = ;
edge[tot].next = head[u]; head[u] = tot++;
edge[tot].to = u; edge[tot].cap = ; edge[tot].flow = ;
edge[tot].next = head[v]; head[v] = tot++;
} int Q[MAXN];
void BFS(int start, int end)
{
memset(dep,-,sizeof(dep));
memset(gap,,sizeof(gap));
dep[end] = ;
gap[] = ;
int front = , rear = ;
Q[rear++] = end;
while(front!=rear)
{
int u = Q[front++];
for(int i = head[u]; i!=-; i=edge[i].next)
{
int v = edge[i].to;
if(dep[v]!=-) continue;
Q[rear++] = v;
dep[v] = dep[u]+;
gap[dep[v]]++;
}
}
} int S[MAXN];
int sap(int start, int end, int N)
{
BFS(start, end);
memcpy(cur,head,sizeof(head));
int top = ;
int u = start;
int ans = ;
while(dep[start]<N)
{
if(u==end)
{
int Min = INF;
int inser;
for(int i = ; i<top; i++)
if(Min>edge[S[i]].cap-edge[S[i]].flow)
{
Min = edge[S[i]].cap-edge[S[i]].flow;
inser = i;
}
for(int i = ; i<top; i++)
{
edge[S[i]].flow += Min;
edge[S[i]^].flow -= Min;
}
ans += Min;
top = inser;
u = edge[S[top]^].to;
continue;
} bool flag = false;
int v;
for(int i = cur[u]; i!=-; i = edge[i].next)
{
v = edge[i].to;
if(edge[i].cap-edge[i].flow && dep[v]+==dep[u])
{
flag = true;
cur[u] = i;
break;
}
} if(flag)
{
S[top++] = cur[u];
u = v;
continue;
} int Min = N;
for(int i = head[u]; i!=-; i = edge[i].next)
if(edge[i].cap-edge[i].flow && dep[edge[i].to]<Min)
{
Min = dep[edge[i].to];
cur[u] = i;
}
if((--gap[dep[u]])==) break;
gap[dep[u]=Min+]++;
if(u!=start) u = edge[S[--top]^].to;
}
return ans;
} int main()
{
int T, n, m;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n,&m);
int start, end, le = INF, ri = -INF;
for(int i = ; i<=n; i++)
{
int x, y;
scanf("%d%d", &x,&y);
if(x<le) { le = x; start = i; }
if(x>ri) { ri = x; end = i; }
} init();
for(int i = ; i<=m; i++)
{
int u, v, c;
scanf("%d%d%d", &u,&v,&c);
add(u, v, c);
add(v, u, c);
} cout<< sap(start, end, n) <<endl;
}
}

HDU4280 Island Transport —— 最大流 ISAP算法的更多相关文章

  1. hdu4280 Island Transport 最大流

    In the vast waters far far away, there are many islands. People are living on the islands, and all t ...

  2. Hdu4280 Island Transport 2017-02-15 17:10 44人阅读 评论(0) 收藏

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

  3. CCF(引水入城:60分):最大流+ISAP算法

    引水入城 201703-5 这从题目分析来看很像最大流的问题,只需要增加一个超级源点和一个超级汇点就可以按照题意连边再跑最大流算法. 因为数据量太大了,肯定会超时.但是没有想到可行的解决方法. #in ...

  4. HDU4280 Island Transport

    ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...

  5. HDU4280:Island Transport(最大流)

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

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

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

  7. HDU-4280-Island Transport(网络流,最大流, ISAP)

    链接: https://vjudge.net/problem/HDU-4280 题意: In the vast waters far far away, there are many islands. ...

  8. Hdu 4280 Island Transport(最大流)

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

  9. P3376 【模板】网络最大流( Edmonds-krap、Dinic、ISAP 算法)

    P3376 [模板]网络最大流( Edmonds-krap.Dinic.ISAP 算法) 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S ...

随机推荐

  1. C#.net磁盘管理以及文件操作

    原文发布时间为:2008-08-08 -- 来源于本人的百度文章 [由搬家工具导入]    需要引入的命名空间: using System.IO;using System.Text; private ...

  2. poj2513字典树+欧拉图判断+并查集断连通

    题意:俩头带有颜色的木棒,要求按颜色同的首尾相连,可能否? 思路:棒子本身是一条边,以俩端为顶点(同颜色共点),即求是否有无向图欧拉路(每条棒子只有一根, 边只能用一次,用一次边即选一次棒子). 先判 ...

  3. poj1149最大流经典构图神题

    题意:n个顾客依次来买猪,有n个猪房,每个顾客每次可以开若干个房子,买完时,店主可以调整这位顾客 开的猪房里的猪,共m个猪房,每个猪房有若干猪,求最多能卖多少猪. 构图思想:顾客有先后,每个人想要的猪 ...

  4. [Bzoj3675][Apio2014]序列分割(斜率优化)

    3675: [Apio2014]序列分割 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 4021  Solved: 1569[Submit][Stat ...

  5. 【mac】mac上使用brew 安装速度慢/每次使用brew 都会卡在updating homebrew不动/更换homebrew的镜像源

    有没有出现一下这样的情况: 如果有,请继续往下走 1.打开mac的命令窗口,键入如下命令 cd /usr/local/Homebrew 2.更换homebrew的默认源[更换为中科大的镜像源] git ...

  6. Android 集成支付宝支付详解

    一说到支付宝,相信没有人不知道,生活中付款,转账都会用到. 今天来详细介绍下在Android中如何集成支付宝支付到自己的APP中去.让APP能够拥有方便,快捷的支付功能. 准备工作: 商户在b.ali ...

  7. IDEA中Thrift插件配置

    方法一:直接在IDEA界面中配置 打开IDEA的插件中心,搜索 Thrift 即可安装 方法二:手动下载Thrift插件安装 有时像在IDEA中安装Lombok插件一样,有时由于网络原因,方法一不奏效 ...

  8. node 爬虫 --- 批量下载图片

    步骤一:创建项目 npm init 步骤二:安装 request,cheerio,async 三个模块 request 用于请求地址和快速下载图片流. https://github.com/reque ...

  9. mysql 存储过程(支持事务管理)

    CREATE DEFINER=`root`@`localhost` PROCEDURE `createBusiness`(parameter1 int) BEGIN #Routine body goe ...

  10. 【转载】NULL,"",String.Empty三者在C#中的区别

    (1)NULLnull 关键字是表示不引用任何对象的空引用的文字值.null 是引用类型变量的默认值.那么也只有引用型的变量可以为NULL,如果int i=null,的话,是不可以的,因为Int是值类 ...