HDU 1595find the longest of the shortest(spfa)

大模型-高通平台性能测试示例-2 在QNN中,可以使用(genis-t2t-run)和这两个工具来进行推理的性能分析。支持在QNX操作系统或Android操作系统上进行性能分析。:提供基本的性能数据,如运行时间、资源消耗等。:提供更详细的性能数据,可能包括各个操作的执行时间、资源使用情况等。:是指在性能分析的同时进行代码质量检查,以发现潜在的问题。:是指跟踪和分析神经网络中各个操作的性能,以优化网络结构或参数。 阅读详情

Problem Description
Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn't live in the same city, she started preparing for the long journey.We know for every road how many minutes it takes to come from one city to another.
Mirko overheard in the car that one of the roads is under repairs, and that it is blocked, but didn't konw exactly which road. It is possible to come from Marica's city to Mirko's no matter which road is closed.
Marica will travel only by non-blocked roads, and she will travel by shortest route. Mirko wants to know how long will it take for her to get to his city in the worst case, so that he could make sure that his girlfriend is out of town for long enough.Write a program that helps Mirko in finding out what is the longest time in minutes it could take for Marica to come by shortest route by non-blocked roads to his city.
 

Input
Each case there are two numbers in the first row, N and M, separated by a single space, the number of towns,and the number of roads between the towns. 1 ≤ N ≤ 1000, 1 ≤ M ≤ N*(N-1)/2. The cities are markedwith numbers from 1 to N, Mirko is located in city 1, and Marica in city N.
In the next M lines are three numbers A, B and V, separated by commas. 1 ≤ A,B ≤ N, 1 ≤ V ≤ 1000.Those numbers mean that there is a two-way road between cities A and B, and that it is crossable in V minutes.
 

Output
In the first line of the output file write the maximum time in minutes, it could take Marica to come to Mirko.
 

Sample Input
  
5 6 1 2 4 1 3 3 2 3 1 2 4 4 2 5 7 4 5 1 6 7 1 2 1 2 3 4 3 4 4 4 6 4 1 5 5 2 5 2 5 6 5 5 7 1 2 8 1 4 10 2 3 9 2 4 10 2 5 1 3 4 7 3 5 10
 

Sample Output
  
11 13 27
 

Author
ailyanlu
 

Source
 

Recommend
8600   |   We have carefully selected several similar problems for you:   1599  1596  1142  1217  1597 

题目意思:先求1到n最短路,然后删除一条边,求得的第二长的1到n最短路的值?


思路:spfa的过程中记录路径,然后删除最短路中的边求得答案



#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

#define N 1005
#define INF 0x3f3f3f3f

int n,m,vis[N],use[N][N];
int head[N],dis[N];
int num,pre[N];

struct stud{
int to,next;
int va;
}e[N*N];

void build(int u,int v,int va)
{
	e[num].to=v;
	e[num].va=va;
	e[num].next=head[u];
	head[u]=num++;
}

void spfa()
{
	int i,j;
	queue<int>q;
	memset(dis,INF,sizeof(dis));
	memset(vis,0,sizeof(vis));
	vis[1]=1;
	dis[1]=0;
	q.push(1);
	pre[1]=-1;
	int cur;
	while(!q.empty())
	{
		cur=q.front();
		q.pop();
		vis[cur]=0;
		for(i=head[cur];i!=-1;i=e[i].next)
		{
			int x=e[i].to;
			if(dis[x]>dis[cur]+e[i].va)
			{
				dis[x]=dis[cur]+e[i].va;
				pre[x]=cur;
				if(!vis[x])
				{
					vis[x]=1;
					q.push(x);
				}
			}
		}
	}
}

int work()
{
	int i,j;
	memset(dis,INF,sizeof(dis));
	memset(vis,0,sizeof(vis));
	queue<int>q;
	q.push(1);
	vis[1]=1;
	dis[1]=0;
	int cur;

	while(!q.empty())
	{
		cur=q.front();
		q.pop();
		vis[cur]=0;
		for(i=head[cur];i!=-1;i=e[i].next)
		{
			int x=e[i].to;
			if(use[cur][x]&&dis[x]>dis[cur]+e[i].va)
			{
				dis[x]=dis[cur]+e[i].va;
				if(!vis[x])
				{
					q.push(x);
					vis[x]=0;
				}
			}
		}
	}
	return dis[n];
}

int main()
{
	int i,j,u,v,va;
	while(~scanf("%d%d",&n,&m))
	{
		memset(use,0,sizeof(use));
		memset(head,-1,sizeof(head));
		num=0;
		while(m--)
		{
			scanf("%d%d%d",&u,&v,&va);
			use[u][v]=use[v][u]=1;
			build(u,v,va);
			build(v,u,va);
		}
		spfa();
		int ans=dis[n];

		for(i=n;pre[i]!=-1;i=pre[i])
		{
			int x=pre[i];
			use[i][x]=use[x][i]=0;
			ans=max(work(),ans);
			use[i][x]=use[x][i]=1;
		}
		printf("%d\n",ans);
	}
	return 0;
}




Mujoco xml actuator 在MuJoCo中,actuator(执行器) 是用于定义外部力或力矩的机制,这些力或力矩可以作用于关节、肌腱或身体。执行器可以模拟各种类型的驱动器,如电机、液压缸、肌肉等。它们通过定义传输(transmission)和力生成机制(force generation)来实现对模型的控制。 阅读详情

相关推荐

MS1030超声波流量计电路实战:如何用15ps精度优化水表设计(附配置代码)

本文深入探讨了如何利用MS1030超声波流量计芯片实现15ps高精度测量,以优化水表设计。文章从系统误差分配出发,详细解析了硬件电路设计要点、SPI通信配置及核心优化技巧,如利用可编程偏置电压和8回波累加功能来提升抗干扰能力与测量稳定性,并附有实用的配置代码示例。

svm4gardener的博客 332

hdu 1595 find the longest of the shortest (dijkstra + spfa)

find the longest of the shortest 题目链接:Problem - 1595 题目大意:现有一个无向图,其中某一条边不存在(要删除),求所有情况中最短路里的最大值。 题目分析: 思路一:枚举m条边,一一删除进行spfa求出最短路,然后比较出最大值。(超时) 思路二:先利用dijkstra求出最短路,再在最短路里枚举个边,一一删除进行spfa求出最短

GrEedWish_X的专栏 586

Unity事件总线第一篇:为什么你的游戏需要一个事件总线?

本文探讨了游戏开发中常见的跨模块调用导致代码强耦合的问题。通过一个攻击按钮触发角色攻击、怪物掉血和血条更新的案例,分析了直接调用方式带来的维护困难、扩展性差和模块重用性低等弊端。文章提出使用事件总线(Event Bus)作为解决方案,通过发布-订阅模式实现模块解耦。重构后的代码中,各模块只需与事件总线交互,彼此不再直接依赖。这种设计使得新增功能(如音效)无需修改现有代码,大大提高了系统的可维护性和扩展性,同时增强了模块的重用性,完美体现了开闭原则。

qq_46348216的博客 1298

HDU - 1595 - find the longest of the shortest (最短路)

题意: 去掉一条边的最短路中最长的是多少。 不需要全部枚举,只需枚举最短路中的边即可,因为去掉一条边相当于距离无限大,最短路还是原来的,只有改变最短路中的边才有可能改变最短路的大小。 #include &lt;bits/stdc++.h&gt; using namespace std; const int maxn = 1010; const int inf = 0x3f3f3f3f; i...

刘二狗的博客 348

lammps建模(电解液)opls-aa力场的基本流程

lammps建模(电解液)opls-aa力场的基本流程

syj0922的博客 2133

卡方分布的前世今生:一个统计概念的演化史

本文追溯了卡方分布从19世纪末的理论雏形到现代统计推断核心工具的发展历程。从Karl Pearson的数学奠基到Ronald Fisher的理论完善,卡方分布在医学研究、社会科学和机器学习等领域展现出广泛应用。文章通过代码示例和性质分析,揭示了这一统计概念如何持续推动数据科学创新。

weixin_29251567的博客 390

hdu1595(枚举+最短路,Dijkstra/SPFA)

题目链接:hdu1595 Dijkstra:515MS /* 题意: 求删掉任意一条边的最长最短路 思路: 首先求出最短路,同时记录下路径,接着枚举最短路上 每一条边(将此边切段),在求最短路,求这些最短路中的最长路 */ #include #include #include #include #include #include using namespace

no pains,no gains 1122

零基础学习CANoe Panel(5)——改变变量的值,控件图像也改变,这是怎么回事?

Panel 中控件的图像随着值变化,是怎么回事?

蚂蚁小兵 2145

hdu 1595(最短路变形)

hdu 1595 (1)题意: 随便去掉一条边,最坏情况下的最短路是多少。 (2)思路: 先求出正常情况下的最短路,然后枚举删除正常最短路上的边,判断最坏的情况是多少。 (3)代码: #include<iostream> #include<cstdio> #include<cstring> #include<queue&gt...

积少成多,水滴石穿 382

RK3588平台开发系列讲解(USB篇)UAC初识

📢本篇将介绍RK3588平台`UAC`的配置使用。

内核笔记 3878

13《CAN总线五种错误类型,故障判定全解析》

CAN总线规定,发送节点在发送完EOF字段后,会留出一个ACK Slot(应答槽)。这个槽里,发送节点自己会输出隐性电平(逻辑1),然后“期待”至少有一个其他节点在这个槽里把它拉成显性电平(逻辑0)。如果这个槽结束时仍然是隐性电平,发送节点就判定:刚才那帧报文,没有任何一个节点成功接收——这就是应答错误。简单说,就是“我喊了一嗓子,却没人应声”。

2401_88858637的博客 264

hdu 1595 find the longest of the shortest ( spfa + 枚举 )

1 解题思路 1.1 题目大意     给出一个无向图,Marica在结点1,Mirko在结点n,其中有一条边损坏了,但并不知道是哪条,Marica选的路一定是最短路,求最坏情况下Marica要走的路程是多长。 1.2 题目分析     一开始我通过枚举每条边为坏边,将其设为不可达,然后求1-N的最短距离,最后取一个最大值,结果超时了。然后才想到如果我将不是最短路径上的边设为不可达对最短距

时空飞扬的专栏 604

【unity游戏开发入门到精通——UGUI】文本控件 —— TextetMeshPro新文本控件(TextMeshPro - Text(UI)和TextMeshPro - Text)

文本组件是UGUI中最常用的组件,它的作用是对文本数据进行处理并显示。UGUI的文本组件可以分两为种——Text旧文本控件、TextMeshPro新文本组件。本文主要是介绍TextMeshPro新文本控件,而TextMeshPro新文本控件又可以分为两种——TextMeshPro - Text(UI)和TextMeshPro - Text。TextMeshPro是Unity收购的一个第三方插件,现在已经自动内置到编辑器中,只要使用一次就会自动导入到工程。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 3752

hdu1595(spfa) find the longest of the shortest

题目链接: huangjing 思路:因为这个女人是从最短路走,那么首先找出最短路,然后拆边,然后再找最短路,最后求出最长时间即可。 代码里还有递归法求最短路径。。 题目: find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K

大洋深处 984

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

hdu 1595 find the longest of the shortest (spfa)

记录最短路上的路径依次枚举删掉,看看剩下的最短路最大值是多少。 #include #include #include #include using namespace std; #define N 1005 const int inf = 1 << 28; struct node{ int to, nxt, w; }e[N*N]; int dis[N], vis[N]; int

uuuuuu 533

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

find the longest of the shortest (hdu 1595 SPFA+枚举)

先求整个的最短路,并记录下最短路经,再分别枚举删除最短路经上的每一条边,并再次求最短路,答案即最长的那条最短路。

@you! 1309

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU1595find the longest of the shortest(SPFA,删边求最短路中的最长路)

find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2076    Accepted Submission(s): 732 Problem Description

青山绿水之辈 专栏 732

hdu 1595 find the longest of the shortest(最短路spfa)

一个人要从1走到N点,中间可能某一条路会断掉,求最短路最坏的情况, 也就是断掉某条路时,最短路径最长。 枚举删边求最短路 #include #include #include #include #include #define MAXN 2005 #define MAXM 2005*2005 #define INF 0x1f1f1f1f using namespace std;

超级码力 618

HDU1595:find the longest of the shortest(spfa+记录路径)

Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn't live in the same city, she started preparing for the long journey.We know fo...

weixin_30819163的博客 162

hdu 1595 find the longest of the shortest(spfa)(存储并枚举最短路径的边)

find the longest of the shortestProblem Description Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn’t live in the same city, she started prepari

Darkarts 591

HDU1595---find the longest of the shortest

http://acm.hdu.edu.cn/showproblem.php?pid=1595 题目大意: 从城市1到城市n有m条双向路,其中有一条路是坏的,但是我们不知道到底哪条路是坏的。 考虑到最坏情况,我们从城市1走到城市n所需要的最少时间是多少。 解题思路: 起初,想法很单纯,枚举每一条边为坏边,求1到n的最短路,然后在这些最短路中取最大值。 思路是正确的,但是会超时

sanmingzi3344的专栏 928

find the longest of the shortest (HDU-1595)(最短路)

Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn't live in the same city, she started preparing for the long journey.We know for every road how m...

菜鸡的博客 261

HDU 1595 find the longest of the shortest

转载请注明出处,谢谢 http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents           by---cxlove 题意是说任意去掉一条边之后的最短路的最长长度为多少。 顶点数为N达到1000的范围,显然枚举所有边再求最短路,复杂度为N^2*O(spfa),会超时的。 仔细想想便知,原图上求一次最短路,如果我们删掉最短路之外的边,之后的最

窝不是爱酱,喵~~~~ 2412

hdu 1595 find the longest of the shortest 最短路dijkstra+枚举

题目链接 题意:给出n个点,m条边,求去除任意一条边的最长最短路。 这题先用求一次最短路,记录下路径。如果去除的边不在路径上,那么最短路不变。所以我们只要考虑去除最短路上的边的情况。枚举最短路上的边删除,求最短路,注意要还原边。 这题用spfa的邻接矩阵形式怎么也过不了,一直TLE。代码不变,换成dijkstra之后就能过了。不知道是不是稠密图的原因,spfa在这种情况下没有dijkstra

弱菜zc 1027

hdu1595 find the longest of the shortest(dijkstra+枚举)

http://acm.hdu.edu.cn/showproblem.php?pid=1595 题意:玛丽卡很生气因为她知道她男友米尔科交到了新的女朋友,于是要去找他算账。但是他们不在一个城市,玛丽卡在N,米尔科在1。米尔科无意中听到有一条路在修路,但是不知道是哪一条。他想让他的新女友去别的地方躲一躲,已知玛丽卡走的肯定是最短路,但是遇到修的路就会走别的路。求问玛丽卡最迟会花费多少时间赶来,好

Iguodala的博客 417
上一篇: POJ 2581 Exact Change Only(dp)
下一篇: codeforce 329B Biridian Forest(bfs)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值