HDU4280 Island Transport —— 最大流 ISAP算法
题目链接: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
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.
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.
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
6
题解:
最大流的裸题,不过对时间效率要求较高。所以就用了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算法的更多相关文章
- hdu4280 Island Transport 最大流
In the vast waters far far away, there are many islands. People are living on the islands, and all t ...
- 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 ...
- CCF(引水入城:60分):最大流+ISAP算法
引水入城 201703-5 这从题目分析来看很像最大流的问题,只需要增加一个超级源点和一个超级汇点就可以按照题意连边再跑最大流算法. 因为数据量太大了,肯定会超时.但是没有想到可行的解决方法. #in ...
- HDU4280 Island Transport
ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...
- HDU4280:Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 4280 Island Transport(网络流,最大流)
HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...
- HDU-4280-Island Transport(网络流,最大流, ISAP)
链接: https://vjudge.net/problem/HDU-4280 题意: In the vast waters far far away, there are many islands. ...
- Hdu 4280 Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- P3376 【模板】网络最大流( Edmonds-krap、Dinic、ISAP 算法)
P3376 [模板]网络最大流( Edmonds-krap.Dinic.ISAP 算法) 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入格式 第一行包含四个正整数N.M.S ...
随机推荐
- Aspose.Words使用代码插入表格
Aspose.Words是一款功能强大的word文档处理控件,在不需要安装word的条件下,可进行word的创建,修改,转换等操作. Aspose.Words可以简单使用该产品提供的DocumentB ...
- Adobe Premiere Pro导入插件开发遇到的一个问题
最近在更新公司一款Premiere Pro CC导入插件的时候,遇到了一个神奇的现象.具体的现象是这样的:我们的插件需要将一些私有的文件数据放到插件中,比如说当前活动的文件名.当插件中收到不同的sel ...
- vue搭建cli脚手架环境(出现问题及解决,主要是node版本低)
Vue 提供了一个官方的cli,为单页面应用 (SPA) 快速搭建繁杂的脚手架. 一.vue cli脚手架 脚手架通过webpack搭建开发环境 使用ES6语法 打包压缩js为一个文件 项目文件在环境 ...
- codevs——1294 全排列
1294 全排列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给出一个n, 请输出n的所有全 ...
- noip2015提高组day2解题报告
1.跳石头 题目描述 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N 块岩石( ...
- gorm 结构体 预加载
结构体构建 type PlansApproval struct { ID uint Plans_Id int //plans编号 UpdateUser int //更新者 ...
- UNIDAC如何驱动MSSQL2000
UNIDAC如何驱动MSSQL2000 如下图,PROVIDER必须设置为PRSQL.默认的PRAUTO,如果操作系统是XP可以,如果是WIN7以上的,不可以. 原因是MSSQL NATIVE 11已 ...
- Go -- NSQ topic和channel的区别
topic:一个可供订阅的话题.channel:属于topic的下一级,一个topic可以有多个channel. 举个例子:topic:比做一个广播,如交通广播.打开收音机,你可以换很多频率,如果换到 ...
- Go -- 如何使用gcore工具获取一个core文件而不重启应用?
问题: 当调试一个程序的时候,理想状态是不重启应用程序就获取core文件. 解决: gcore命令可以使用下面步骤来获取core文件: 1. 确认gdb软件包已经被正确安装. 2. 使用调试参数编译程 ...
- js监听鼠标点击操作
element.addEventListener('click', function() { /* do stuff here*/ }, false);