题目链接: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. Linux 下测试磁盘读写 I/O 速度的方法汇总

    在分布式异构存储系统中,我们经常会需要测量获取不同节点中硬盘/磁盘的读写 I/O 速度,下面是 Linux 系统下一些常用测试方法(之后不定期更新): 1.使用 hdparm 命令这是一个是用来获取A ...

  2. 下载安装webstrom及激活

    太久没在新电脑上安装websrtom,又有点忘了咋激活. 一.安装 1.直接在浏览器搜索webstrom,打开官网,直接点击download.如下图 2.打开安装包,开始安装,直接点击 next 3. ...

  3. JQuery select 编程时选中原有的值

    js 此为核心代码 $(document).ready(function(){ $("#carTypeId").attr("value",'${carInfo. ...

  4. 《深入理解mybatis原理》 MyBatis的二级缓存的设计原理

    MyBatis的二级缓存是Application级别的缓存,它可以提高对数据库查询的效率,以提高应用的性能.本文将全面分析MyBatis的二级缓存的设计原理. 如上图所示,当开一个会话时,一个SqlS ...

  5. Ionic 学习笔记

    本文为原创,转载请注明出处: cnzt       文章:cnzt-p http://www.cnblogs.com/zt-blog/p/7831153.html 注: 本篇学习笔记基于Ionic 3 ...

  6. scrapy的allowed_domains设置含义

    设置allowed_domains的含义是过滤爬取的域名,在插件OffsiteMiddleware启用的情况下(默认是启用的),不在此允许范围内的域名就会被过滤,而不会进行爬取 但是有一个问题:像下面 ...

  7. 改动C:\WINDOWS\system32\drivers\etc\hosts 文件有什么作用

    host是一个没有扩展名的系统文件,能够用记事本等工具打开,其作用就是将一些常常使用的网址域名与其相应的IP地址建立一个关联"数据库".当用户在浏览器中输入一个须要登录的网址时,系 ...

  8. Shiro源代码分析之两种Session的方式

    1.Shiro默认的Session处理方式 <!-- 定义 Shiro 主要业务对象 --> <bean id="securityManager" class=& ...

  9. IOS开发——网络编程总汇

    关于IOS的网络编程,大家都会想到C实现的底层BSD ,CFNetwork和NSURL之类的库,虽然如今非常多第三方库非常方便,可是作为一名开发人员,也须要了解底层代码. 以下的思维导图是关于眼下开发 ...

  10. 二:redis 的hash类型相关操作

    =====================二种:hash类型================== 介绍:redis -> hash是一个string类型的field和value的映射表 hash ...