链接:

https://vjudge.net/problem/HDU-4280

题意:

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.

思路:

考虑无向图,只需给反向边加上容量,同时图的点很多,使用ISAP算法.

找了很久,看了很久..找的代码bfs写错了(貌似?).最后很久才改出来.

代码:

#include <bits/stdc++.h>
using namespace std; const int MAXN = 1e5+10;
const int INF = 1e9; struct Edge
{
int from, to, flow, cap;
}; int Pre[MAXN], Cur[MAXN];
int Num[MAXN], Vis[MAXN];
int Dis[MAXN];
vector<int> G[MAXN];
vector<Edge> edges;
int n, m, s, t; void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge{from, to, 0, cap});
edges.push_back(Edge{to, from, 0, cap});
int len = edges.size();
G[from].push_back(len - 2);
G[to].push_back(len - 1);
} void Bfs()
{
memset(Vis, 0, sizeof(Vis));
queue<int> que;
que.push(t);
Vis[t] = 1;
Dis[t] = 0;
while (!que.empty())
{
int u = que.front();
que.pop();
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]^1];
if (Vis[e.from] == 0 && e.cap > e.flow)
{
Vis[e.from] = 1;
que.push(e.from);
Dis[e.from] = Dis[u]+1;
}
}
}
} int Augment()
{
// cout << 1 << endl;
int x = t, flow = INF;
while (x != s)
{
Edge &e = edges[Pre[x]];
// cout << e.from << ' ' << e.to << endl;
flow = min(flow, e.cap-e.flow);
x = e.from;
}
// cout << flow << endl;
x = t;
while (x != s)
{
edges[Pre[x]].flow += flow;
edges[Pre[x]^1].flow -= flow;
x = edges[Pre[x]].from;
}
return flow;
} int MaxFlow()
{
int flow = 0;
Bfs();
memset(Num, 0, sizeof(Num));
for (int i = 0;i < n;i++)
Num[Dis[i]]++;
int x = s;
memset(Cur, 0, sizeof(Cur));
while (Dis[s] < n)
{
if (x == t)
{
flow += Augment();
x = s;
}
bool ok = false;
for (int i = Cur[x];i < G[x].size();i++)
{
Edge &e = edges[G[x][i]];
if (e.cap > e.flow && Dis[x] == Dis[e.to]+1)
{
ok = true;
Pre[e.to] = G[x][i];
Cur[x] = i;
x = e.to;
break;
}
}
if (!ok)
{
int line = n-1;
for (int i = 0;i < G[x].size();i++)
{
Edge &e = edges[G[x][i]];
if (e.cap > e.flow)
line = min(line, Dis[e.to]);
}
if (--Num[Dis[x]] == 0)
break;
Dis[x] = line+1;
Num[Dis[x]]++;
Cur[x] = 0;
if (x != s)
x = edges[Pre[x]].from;
}
}
return flow;
} int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d %d", &n, &m);
for (int i = 1;i <= n;i++)
G[i].clear();
edges.clear();
int mmin = INF, mmax = -INF;
int u, v, w;
for (int i = 1;i <= n;i++)
{
scanf("%d %d", &u, &v);
if (u < mmin)
s = i, mmin = u;
if (u > mmax)
t = i, mmax = u;
}
for (int i = 1;i <= m;i++)
{
scanf("%d %d %d", &u, &v, &w);
AddEdge(u, v, w);
}
int res = MaxFlow();
printf("%d\n", res);
} return 0;
}

HDU-4280-Island Transport(网络流,最大流, ISAP)的更多相关文章

  1. Hdu 4280 Island Transport(最大流)

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

  2. HDU 4280 Island Transport(网络流)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...

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

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

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

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

  5. HDU 4280 Island Transport

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

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

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

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

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

  8. HDU4280:Island Transport(最大流)

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

  9. POJ 1459-Power Network(网络流-最大流-ISAP)C++

    Power Network 时间限制: 1 Sec  内存限制: 128 MB 题目描述 A power network consists of nodes (power stations, cons ...

随机推荐

  1. 写入mongodb

    https://blog.csdn.net/u013421629/article/details/78885079 https://www.jianshu.com/p/7d14c3ad810f  可视 ...

  2. 浅谈call apply bind的区别

    这三个方法的用法非常相似,将函数绑定到上下文中,即用来改变函数中this的指向.举个例子: var zlw = { name: "zlw", sayHello: function ...

  3. Spring MVC静态资源处理——<mvc:resources /> ||<mvc:default-servlet-handler />

    优雅REST风格的资源URL不希望带 .html 或 .do 等后缀.由于早期的Spring MVC不能很好地处理静态资源,所以在web.xml中配置DispatcherServlet的请求映射,往往 ...

  4. robotframework之使用cookies登陆

    有的系统是使用cookies保持登陆的,而RF的Request库里面没有像Selenium2Library里面一样操作cookies的关键字,若接口需要登录则只能用UI自动化先登录,然后再将cooki ...

  5. delphi assigned函数的用法

    if not Assigned(Modeless) then Assigned()什么意思! assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(fa ...

  6. Web测试常用的链接测试工具

    1.Xenu Link Sleuth 详细解说地址:http://home.snafu.de/tilman/xenulink.htm http://pan.baidu.com/s/1qY3Tp4C(英 ...

  7. HTML5实现绘制几何图形

    HTML5新增了一个<canvas.../>属性.该元素自身并不绘制图形,只是相当于一张空画布.如果开发者需要向<canvas.../>上绘制图形则必须使用JavaScript ...

  8. python学习之路 目录

    python Python基础-1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while python基础-2 编码转换 pycharm 配 ...

  9. 虚拟机上首次安装Ubuntu后 root密码设置

    虚拟机下安装ubuntu后root密码设置 问题描述: 在虚拟机下安装了ubuntu中要输入用户名,一般情况下大家都会输入一个自己的网名或绰号之类的,密码也在这时设置过了. 但是当安装成功之后,使用命 ...

  10. shell脚本每隔几秒执行

    while true do cmd(shell 命令) sleep x(x为秒数) done ————————————————版权声明:本文为CSDN博主「这年头起名真难3232」的原创文章,遵循 C ...