hdu4280 Island Transport 最大流 ISAP模板题

【RF】Receiver Function接收函数:从理论到实践的深度解析 本文深入解析地震学中的接收函数(Receiver Function, RF)技术,从理论原理到实践操作。文章将RF比作地球的“听诊器”,详细阐述了其通过反褶积剥离震源影响、揭示地下结构(如莫霍面)的核心机制,并提供了使用Python和rf库进行数据处理、计算、动校正与叠加的完整实战流程,同时探讨了其应用、局限性与常见问题的解决方案。 阅读详情

Island Transport

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


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


#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <iostream>
#include <cstdlib>

using namespace std;

const int maxn = 100005, INF = 0x7fffffff;

int s;         // 源点
int t;         // 汇点
int p[maxn];   // 可增广路上的上一条弧的编号
int num[maxn]; // 和 t 的最短距离等于 i 的节点数量
int cur[maxn]; // 当前弧下标
int d[maxn];   // 残量网络中节点 i 到汇点 t 的最短距离
bool vis[maxn];
int T, n, m;

struct Edge {
	int from, to, cap, flow;
	Edge() {}
	Edge(int from, int to, int cap, int flow) : from(from), to(to), cap(cap), flow(flow) {}
};
vector<int> G[maxn];
vector<Edge> edges;

void AddEdge(int from, int to, int cap) {
	edges.push_back(Edge(from, to, cap, 0));
	edges.push_back(Edge(to, from, 0, 0));
	int len = edges.size();
	G[from].push_back(len - 2);
	G[to].push_back(len - 1);
}

// 预处理, 反向 BFS 构造 d 数组
bool BFS() {
	memset(vis, 0, sizeof(vis));
	queue<int> Q;
	Q.push(t);
	vis[t] = 1;
	d[t] = 0;
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (int i = 0; i < G[u].size(); i++) {
			Edge &e = edges[G[u][i] ^ 1];
			if (!vis[e.from] && e.cap > e.flow) {
				vis[e.from] = true;
				d[e.from] = d[u] + 1;
				Q.push(e.from);
			}
		}
	}
	return vis[s];
}

// 增广
int Augment()
{
	int x = t, a = INF;
	// 从汇点到源点通过 p 追踪增广路径, a 为一路上最小的残量
	while (x != s) {
		Edge &e = edges[p[x]];
		a = min(a, e.cap - e.flow);
		x = edges[p[x]].from;
	}
	x = t;
	// 从汇点到源点更新流量
	while (x != s) {
		edges[p[x]].flow += a;
		edges[p[x] ^ 1].flow -= a;
		x = edges[p[x]].from;
	}
	return a;
}

int Maxflow()
{
	int flow = 0;
	BFS();
	memset(num, 0, sizeof(num));
	for (int i = 0; i < n; i++) num[d[i]]++;
	int x = s;
	memset(cur, 0, sizeof(cur));
	while (d[s] < n) {
		if (x == t) {
			flow += Augment();
			x = s;
		}
		bool advanced = false;
		for (int& i = cur[x]; i < G[x].size(); i++) {  //int& i,当前弧优化
			Edge& e = edges[G[x][i]];
			if (e.cap > e.flow && d[x] == d[e.to] + 1) {
				advanced = true;
				p[e.to] = G[x][i];
				cur[x] = i;
				x = e.to;
				break;
			}
		}
		if (!advanced) { // retreat
			int m = n - 1;
			for (int i = 0; i < G[x].size(); i++) {
				if (edges[G[x][i]].cap > edges[G[x][i]].flow) {
					m = min(m, d[edges[G[x][i]].to]);
				}
			}
			if (--num[d[x]] == 0) break; // gap优化
			num[d[x] = m + 1]++;
			cur[x] = 0;
			if (x != s) x = edges[p[x]].from;
		}
	}
	return flow;
}

int main()
{
	cin >> T;
	while (T--) {
		scanf("%d%d", &n, &m);
		edges.clear();
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= n; i++) {
			G[i].clear();
		}
		int wm = INF, em = -INF, wi, ei;
		for (int i = 1; i <= n; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			if (x < wm) {
				wi = i;
				wm = x;
			}
			if (x > em) {
				ei = i;
				em = x;
			}
		}
		for (int i = 1; i <= m; i++) {
			int u, v, c;
			scanf("%d%d%d", &u, &v, &c);
			AddEdge(u, v, c);
			AddEdge(v, u, c);
		}
		s = wi; t = ei;
		printf("%d\n", Maxflow());
	}
	return 0;
}




Dinic超时代码:

#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <iostream>
#include <cstdlib>
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int maxn = 100005, INF = 0x7fffffff;
int T, n, m, wm, em, wi, ei;

struct Edge {
	int from, to, cap, flow;
	Edge() {}
	Edge(int from, int to, int cap, int flow) : from(from), to(to), cap(cap), flow(flow) {}
};

vector<Edge> edges;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn], cur[maxn];

struct Dinic {
	int len, s, t;
	void Init() {
		edges.clear();
		for (int i = 1; i <= n; i++) {
			G[i].clear();
		}
		memset(d, 0, sizeof(d));
	}

	void AddEdge(int from, int to, int cap) {
		edges.push_back(Edge(from, to, cap, 0));
		edges.push_back(Edge(to, from, 0, 0));
		len = edges.size();
		G[from].push_back(len - 2);
		G[to].push_back(len - 1);
	}

	bool BFS() {
		memset(vis, 0, sizeof(vis));
		queue<int> Q;
		Q.push(s);
		d[s] = 0;
		vis[s] = 1;
		while (!Q.empty()) {
			int x = Q.front(); Q.pop();
			for (int i = 0; i < G[x].size(); i++) {
				Edge& e = edges[G[x][i]];
				if (!vis[e.to] && e.cap > e.flow) {
					vis[e.to] = 1;
					d[e.to] = d[x] + 1;
					Q.push(e.to);
				}
			}
		}
		return vis[t];
	}

	int DFS(int x, int a) {
		if (x == t || a == 0) return a;
		int flow = 0, f;
		for (int& i = cur[x]; i < G[x].size(); i++) {
			Edge& e = edges[G[x][i]];
			if (d[x] + 1 == d[e.to] && (f = DFS(e.to, min(a, e.cap - e.flow))) > 0) {
				e.flow += f;
				edges[G[x][i] ^ 1].flow -= f;
				flow += f;
				a -= f;
				if (a == 0) break;
			}
		}
		return flow;
	}

	int Maxflow(int s, int t) {
		this->s = s; this->t = t;
		int flow = 0;
		while (BFS()) {
			memset(cur, 0, sizeof(cur));
			flow += DFS(s, INF);
		}
		return flow;
	}
};

int main()
{
	Dinic d;
	cin >> T;
	while (T--) {
		scanf("%d%d", &n, &m);
		d.Init();
		wm = INF, em = -INF;
		for (int i = 1; i <= n; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			if (x < wm) {
				wi = i;
				wm = x;
			}
			if (x > em) {
				ei = i;
				em = x;
			}
		}
		for (int i = 1; i <= m; i++) {
			int u, v, c;
			scanf("%d%d%d", &u, &v, &c);
			d.AddEdge(u, v, c);
			d.AddEdge(v, u, c);
		}
		printf("%d\n", d.Maxflow(wi, ei));
	}
	return 0;
}


YOLO26改进 - SPPF模块 | 发论文神器!LSKA注意力改进SPPF,增强多尺度特征提取能力,高效涨点!!! 本文介绍了Large Separable Kernel Attention (LSKA)模块及其在YOLO26中的结合应用。LSKA旨在解决Visual Attention Networks (VAN)使用大内核卷积时的计算效率问题,通过将2D深度卷积层的卷积核分解为级联的水平和垂直1-D卷积核,降低了计算复杂度和内存占用,且使VAN更关注物体形状。我们将集成LSKA的SPPF_LSKA模块引入YOLO26,大量实验表明,改进后的模型在对象识别、检测、分割和稳健性测试上表现出色。 阅读详情

相关推荐

Triton推理服务器实战:如何为PaddleOCR的ONNX模型配置动态批处理和并发推理

本文详细介绍了如何使用Triton推理服务器为PaddleOCR的ONNX模型配置动态批处理和并发推理,以提升GPU利用率和推理性能。通过实战案例和参数调优指南,帮助开发者解决高并发场景下的性能瓶颈问题,实现从实验室到生产环境的高效部署。

weixin_42527160的博客 426

POJ-2455-无向图网络流

题目大意:给定一张无向图,注意可能两点间可能有重边,一个人从地点1到地点n要有t次,问所有路中的最大值最小是多少; 题目解析:首先重边的话图就不可以用邻接矩阵来表示了,要用邻接表来表示,无向图的加边反向边不需要初始化为0应该和正向边一样(看成一对反向边即可);最大值的最小值直接二分即可; AC代码: #include #include #include #

zyz_3_14159的博客 1608

RAG优化知识库检索(4):混合检索技术

混合检索技术在RAG(检索增强生成)系统中的应用显著提升了检索效果。本文探讨了语义检索与关键词检索的优缺点,指出两者在语义理解和精确匹配方面的互补性。通过结合BM25与向量检索,混合检索系统能够更全面地捕捉文档的相关性。文章详细介绍了并行检索、级联检索、稀疏-密集混合表示等多种结合方式,并探讨了权重调整策略,如线性组合、动态权重调整和排序融合算法。此外,稀疏-密集混合检索架构的设计和实现方案也被深入分析,展示了如何通过结合不同检索方法的优势,提升RAG系统的检索质量和效率。

分享一些感兴趣的技术方面 2071

无向图的网络流与最大流问题

1.背景介绍 无向图的网络流与最大流问题是一种经典的计算机科学问题,它在计算机网络、物流、生产线、电路设计等领域具有广泛的应用。在这篇文章中,我们将深入探讨无向图的网络流与最大流问题的核心概念、算法原理、具体操作步骤以及数学模型公式。同时,我们还将通过具体的代码实例来详细解释这些概念和算法,并探讨未来发展趋势与挑战。 1.1 背景介绍 无向图的网络流问题是一种求最大值的优化问题,它的主要目标...

AI天才研究院 985

《拉依达的嵌入式\驱动面试宝典》—C/CPP基础篇(二)

《拉依达的嵌入式\驱动面试宝典》 整合了所有我认为可能遇到的技术面试问题。所有问题及其答案均是我个人学习后查阅资料总结,每个回答都做了仔细的分析,在嵌入式及其驱动面试相关问题解析做到全网独一无二。学习或者转行到嵌入式、驱动开发领域学习的不二之选

拉依达不拉跨的博客 575

【XAI】透视深度学习:CNN与Transformer的可解释性方法

深度学习模型的可解释性方法解析:本文探讨了CNN和Transformer两类主流模型的可解释性技术。针对CNN,介绍了显著性图、类激活图(CAM/Grad-CAM)和基于扰动的方法,通过可视化重要像素区域揭示决策依据。对于Transformer,重点分析了注意力机制可视化及其在文本处理中的应用,并介绍了积分梯度等归因方法。文章包含详细的Python实现示例(使用Captum库),涵盖从MNIST图像显著性分析到BERT文本注意力可视化,为初学者提供了可操作的技术指南。这些方法有助于增强模型透明度,提升AI系

u012133341的博客 381

HDU 4280 Island Transport

Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2042 Accepted Submission(s): 636 Problem Description   In the vast

蛤蛤~ 702

【Qt】QtCreator远程部署、调试程序

1)QtCreator 工具–> 选项 --> 设备 --> 添加2)设备设置向导选择–> Generic Linux Device --> 开启向导3)填写“标识配置的名称”(随便写)、设备IP、用户名 --> 下一步4)选择配对秘密文件,第一次配对,可以不填写,点击“下一步”5)点击“完成”6)设备添加成功,需要再配置SSH端口号、用户名、密码等7)保存SSH登陆密码:验证类型选择默认“Default”–> “创建新密钥”–> “Test”

郭老二 5193

【网络流】最大流:最大流判定,拆点,建图实战

最大流判定 秘密挤奶机 原题链接 给出一张包含NNN个点,PPP条边的无向图,1→N1\rightarrow N1→N走TTT次,每条边最多走111次。 问:TTT条路径中最大边权的最小值。 用dinic+dinic+dinic+二分。 判定问题:在无向图中,删除大于midmidmid的边,查找边权≤mid\leq mid≤mid的边,1→N1\rightarrow N1→N是否存在TTT条没有公共边的路径。 建图:将无向图变为有向图: S=1,T=nS=1,T=nS=1,T=n,最大可行流流量===路

ZYzyZzzz的博客 958

【x265编码器】章节1——x265的lookahead模块分析

目录一、模块功能二、lookahead模块分析1.调用流程2.代码分析Lookahead::addPicture()Lookahead::checkLookaheadQueue()Lookahead::getDecidedPicture()Lookahead::findJob()Lookahead::slicetypeDecide()PreLookaheadGroup::processTasksLookaheadTLD::lowresIntraEstimate()Lookahead::slicetypeAn

vcvdv123的博客 4万+

游戏玩家和排行数据抓取:使用 Python 爬虫抓取游戏中的玩家排名、角色数据和战绩

对于游戏开发者、分析师和玩家本身来说,抓取游戏中的玩家排名、角色数据和战绩信息是一项至关重要的任务。Python提供了强大的爬虫库和数据处理工具,可以帮助我们高效地抓取和分析游戏数据,为游戏分析师、开发者以及玩家本身提供有价值的数据支持。通过本篇博客,我们学习了如何使用Python爬虫技术抓取游戏中的玩家排名、角色数据和战绩。本篇博客将详细介绍如何使用Python编写爬虫来抓取游戏中的玩家排名、角色数据和战绩,并结合最新的技术来实现高效的数据抓取与处理。为了方便后续的数据处理,我们将抓取的数据保存到。

2201_76125261的博客 944

网络流处理无向图 二分+网络流

题意:给定一张无向图,有n个节点p条边, 要求在图中从1到n找到t条路径,并且使这t条路径中的最长边最小, 输出这个最小的最长边 思路:让所有的边值为1,即可知道从s到t有多少条路,二分处理最大值的最小值即可。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algor...

空白 1144

OCR文字识别领域经典论文总结

本篇将介绍文字识别经典论文,内容包括文字检测、文字识别、端到端识别等方法,具体将分别对论文算法简介、思路、代码等几个部分展开介绍。目前各部分只举例经典论文,算法没有全部写完,后续会将在此部分基础上更新更多论文综述及代码实战部分。.................................

专注大数据与人工智能技术分享,欢迎私信加群互相学习! 1万+

HDU 4280Island Transport(网络流之最大流)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4280 这个题是一个纯最大流模板题。。就是用来卡时间的。。还好我会isap算法。。但是坑爹的是一直WA,最后加了个输入优化就过了。。。(仅仅是把输入改了改而已。。)至今不知道为什么。。请好心的看到此博客的大神赐教。。 代码如下: #include #include #include #inc

scf0920 1527

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

hdu 4280 Island Transport(最大流)

hdu 4280 Island TransportDescription   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 ha

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 1303

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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

HDU 4280 Island Transport(网络流,最大流) 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 shi...

dipinzhu4111的博客 198

HDU4280,Island Transport(最大流ISAP)

这道题是最大流的裸题,但是数据很大,时间卡得比较严,前几次是用Dinic的,都超时了,后面改用效率更高的ISAP,3700MS AC。 代码如下: #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<queue> using ...

shamansi99的博客 198

[HDU 4280]Island Transport[SAP]

题目链接:[HDU 4280]Island Transport[SAP] 题意分析: 最西边的岛屿给最东边的岛屿运输,问最大运输能力。 解题思路: 最西边源点,最东边汇点,建边就行。 个人感受: 这题之所以写题解是因为,我竟然把边开的和点一样多= =,然后交上去不是RE而是T。。。。改了各种板子我都质疑人生了= =,结果是边开小了!!!!!教训教训!!!! 具体代码如下: #inc

闲停 639

hdu4280 Island Transport (最大流ISAP算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 #include #include #define MAXN 100002 #define MAXE 400002 #define INF 0x3f3f3f3f struct node { int from,to,next; int cap; }edge[MAXE];

不可不戒 893

G - Island Transport HDU - 4280

G - Island Transport 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 ...

Dch19990825的博客 283

HDU-4280 Island Transport

题目链接:HDU-4280 Island Transport 题意 给出$n$个岛屿$m$条双向航道,岛屿以直角坐标系上的坐标形式给出,每条航道在单位时间有运输量上限,问单位时间内从$x$轴最左边的岛屿到最右边的岛屿最大的运输量。 思路 最大流问题,最左边的岛屿为源点,最右边的岛屿为汇点,按所给航道连边即可,由于是无向边,所以不需要再建容量为0的反向边。$n,m$很大,要用效...

weixin_30699465的博客 178

HDU - 4280 Island Transport 双向图最大流

题目链接 https://vjudge.net/problem/HDU-4280 题意 n个城市,m道路,道路有最大通行量,是双向通行的,求最西边城市到最东边城市最大通行量 思路 裸的最大流,坐标没必要存,记录一下源汇点就行了。 注意道路是双向的,所以建边要双向建边,本来增广路算法反向容量0的边就不用再建了。 代码 #include<cstdio> #include<iostream> #include<iomanip> #include<map> #incl

TheSunspot的博客 399

hdu 4280 Island Transport isap果题

题意:给出n个二维坐标系上的点(其实就是n个点),最左的是起点,最右的是终点,且各只有一个,问从起点到终点的最大流。 建边直接上模板即可 #include #include #include #include #include #include #include #include #include #include #include #include using na

uuuuuu 417

网络流isap算法 -- Island Transport HDU - 4280

Island Transport HDU - 4280 题意: 给一张图,求最大流 思路: isap算法模板 code: #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm> #include<queue> using namespace std; const int maxn = 1e5 + 5; str

dajiangyou123456的博客 209

HDU-4280 Island Transport (最大流 卡时间)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:给你n个岛屿的坐标,让你求从最西边到最东边的最大流 (题目保证只有一个点在最西边,只有一个点在最东边) 这个题比较卡时间 普通 dinic() 9375ms kuangbin模板 4992ms ISAP+bfs初始化+栈优化 3572ms #include &lt...

zx93的博客 227

【HDUOJ】4280 Island Transport

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到最东的那个岛屿 题解:最大流的裸题。输入记得找到最西和最东的岛屿,以及注意是双向边。。这题用的sap. 代码: 1 #include<iostr...

deze1991的专栏 106

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

链接: 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....

weixin_30294021的博客 106
上一篇: hdu5952 Counting Cliques DFS
下一篇: hdu5935 Car 贪心 卡精度
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值