链接:

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. 2018-5 - 凉经 - Mozilla Firefox Ltd - 前端工程师

    北京谋智火狐信息技术有限公司(北京市东城区建国门华润大厦 17 层)过去面试的时候感觉电梯好神奇啊!一边的电梯是直达 18 层以上的,我按了 18 层准备到了再往下走一层,一个老司机和我说要做另一边的 ...

  2. Intellij IDEA 常见问题

    右击项目时,没有 Java Class,只能创建其他文件 IDEA 还没有将这个项目识别为 Maven 项目时,会出现这种情况.此时右键无法创建类. 解决办法: 手动为 IDEA 指定项目类型:如果编 ...

  3. Apache web服务器(LAMP架构)

    1.apache介绍 1).世界上使用率最高的网站服务器,最高时可达70%:官方网站:apache.org 2).http 超文本协议 HTML 超文本标记语言 3).URL 统一资源定位符 http ...

  4. Ubuntu16.04 国内源 source 注意事项

    注意对应关系 Ubuntu16.04 为 xenial 如果贴错了 在你执行 sudo apt-get upgrade 的时候很麻烦.很慢会更新到 另外版本系统中. 被坑过…… 阿里云源 deb ht ...

  5. MySql 性能优化之 Explain

    MySQL 之 Explain 输出分析 背景 前面的文章写过 MySQL 的事务和锁,这篇文章我们来聊聊 MySQL 的 Explain,估计大家在工作或者面试中多多少少都会接触过这个.可能工作中实 ...

  6. Hive-java.lang.ClassNotFoundException: org.apache.hadoop.hive.contrib.serde2.MultiDelimitSerDe

    Task with the most failures(): ----- Task ID: task_1555476136794_8201_m_000000 URL: http://hadoop1:8 ...

  7. [Web 前端] 022 js 的基本数据类型及使用

    1. Javascript 基本数据类型 1.1 分类 类型 释义 boolean 布尔类型,分 true 与 false number 整型,浮点型 string 字符类型 object 对象类型 ...

  8. [Git] 026 config 命令的补充

    少废话,上例子 1. 让命令更醒目 $ git config --global color.ui true 2. 偷懒 $ git config --global alias.st status 使用 ...

  9. 对于出现拒绝访问root用户的解决方案

    提示:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'   由于使用mysql -u root ...

  10. 1、Java调用C语言(本地法)

    这是一个比较麻烦的方法..   一.首先,你要先安装一个VC,我的装在了D:\software\C++\Microsoft Visual Studio   二.我的jdk安装目录是D:\Program ...