hdu4280 Island Transport 最大流 ISAP模板题

Python实战:基于PyG和Stable-Baselines3复现柔性车间调度算法(附数据集) 本文提供了一份基于图神经网络与深度强化学习的柔性车间调度实战指南。通过PyTorch Geometric构建异构图表示车间状态,并利用Stable-Baselines3中的PPO算法训练调度智能体,详细介绍了从环境建模、网络设计到训练评估的完整代码实现,帮助开发者构建可复用的工业级智能调度系统。 阅读详情

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;
}


【AI Agent系列】【阿里AgentScope框架】0. 快速上手:AgentScope框架简介与你的第一个AgentScope程序 这是我们学习的第四款智能体框架了。前面我们学习了 AutoGPT、MetaGPT、LangGraph 等智能体应用开发框架,各有优缺点。今天我们开始学习AgentScope这一款多智能体开发框架。卷起来吧,多看看,多用用,没坏处。 阅读详情

相关推荐

MTK平台LCD驱动开发实战:从零开始点亮你的Android屏幕

本文详细介绍了在MTK平台进行Android LCD驱动开发的完整流程。从理解LK与Kernel双核驱动框架入手,手把手讲解驱动结构体、屏幕参数配置、初始化序列编写以及PLL_CLOCK计算等核心步骤,并提供了系统集成配置与实用的调试避坑指南,帮助开发者高效点亮新屏幕。

terraform7cloud的博客 303

POJ-2455-无向图网络流

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

zyz_3_14159的博客 1611

别再只会用555了!手把手教你用运放和RC电路搭一个50Hz正弦波信号源(附Multisim仿真文件)

本文详细介绍了如何使用运放LM358和RC电路搭建一个精准的50Hz正弦波信号源,涵盖文氏电桥核心原理、单电源供电解决方案、Multisim仿真及实物调试技巧。通过实战指南和优化建议,帮助电子爱好者快速掌握低频信号生成技术,适用于各种测试和校准场景。

weixin_34116482的博客 379

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

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

AI天才研究院 988

了解你的GPU:深入探讨AMD SMI

2024年9月17日 作者:Matt Elliott对于使用AMD硬件的系统管理员和高级用户来说,性能优化和高效的资源监控至关重要。AMD系统管理界面命令行工具`amd-smi`正是为了解决这些需求而设计的。amd-smi是一个多功能的命令行工具,专门用于管理和监控AMD硬件,主要侧重于GPU。作为未来取代`rocm-smi`的工具,`amd-smi`有望成为跨广泛设备的AMD硬件管理的主要工具。

数字人生 4545

华为数通---配置风暴控制案例

风暴控制可以通过阻塞报文或关闭端口来阻断广播、未知组播和未知单播报文的流量。

2301_77081516的博客 1639

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

蛤蛤~ 704

国产平替NeuroSky?实测金牛座TGAM脑电模块,从Arduino到Python的完整数据采集指南

本文详细介绍了国产金牛座TGAM脑电模块的完整使用流程,包括硬件连接、数据采集和Python分析。通过Arduino和Python的实战案例,展示了如何从脑电波传感器获取并解析专注度、放松度等数据,适用于专注力训练和脑机接口开发。

weixin_30735745的博客 595

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

最大流判定 秘密挤奶机 原题链接 给出一张包含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的博客 960

保姆级教程:用Multisim仿真快速上手二极管、MOSFET和IGBT的开关特性

本文提供了一份详细的Multisim仿真教程,帮助读者快速掌握二极管、MOSFET和IGBT的开关特性。通过搭建实验电路、观察波形特征和参数影响分析,深入解析了反向恢复过程、米勒平台现象和拖尾电流效应。适合电力电子初学者和工程师通过仿真建立直观理解,提升电路设计能力。

weixin_29290863的博客 504

YOLOv11目标检测模型性能评价指标详解,涉及混淆矩阵、F1-Score、IoU、mAP、参数量、计算量等,一文打尽所有评价指标

本文主要讲解的是计算机视觉网络模型的性能评价指标,这是每一篇论文中都需要展示的内容。熟悉每一个评价指标也能够帮助我们在训练和改进模型过程中,更好的观察模型的变化效果。

Limiiiing的博客 8439

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

题意:给定一张无向图,有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

WinCCV7.5 笔记5-报表打印

P44 打印液位报警表格 P45 对新建的布局编辑 P46 编辑打印作业

skr? 3983

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

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

scf0920 1528

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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

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

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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的博客 201

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

HDU4280,Island Transport(最大流ISAP)

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

shamansi99的博客 202

[HDU 4280]Island Transport[SAP]

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

闲停 645

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的博客 286

HDU-4280 Island Transport

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

weixin_30699465的博客 179

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 418

网络流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的博客 210

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

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

zx93的博客 228

【HDUOJ】4280 Island Transport

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

deze1991的专栏 107
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址