当前位置:网站首页>7-9 超级玛丽
7-9 超级玛丽
2022-06-22 20:24:00 【白—】
7-9 超级玛丽
假定有n个城堡,编号为1至n,有的城堡之间有道路直接相连,有的城堡之间没有道路直接相连。马里奥现在准备从一个城堡出发前往另一个城堡,它有一个魔法棒,可以瞬时通过一条道路,即以0时间通过这条道路,但魔法棒最多只能用一次。马里奥想以最短的时间到达目的地,请编写程序为马里奥选定一条路线以及在什么地方使用魔法棒。假定所有道路为双向,保证从起点肯定能到达目的地。
输入格式:
输入第一行为4个整数n、s、t、m,分别表示城堡数(编号为1至n,n不超过10000),马里奥所在的起点s和想去的终点t,城堡间的道路数目。接下来m行,每行为3个正整数a、b、c,表示城堡a和城堡b之间有一条道路直接相连,通过该道路需要c分钟。
输出格式:
输出为空格间隔的2个整数,第1个整数为马里奥从起点到目的地所需的最短时间;第2个整数表示使用魔法棒的地点,即城堡编号,若有多个可能的地点,则输出编号最小者。
输入样例:
4 1 4 4
1 2 9
2 4 1
1 3 3
3 4 5
输出样例:
1 1
一直有个点错。。。不晓得哪错了,只有7分
代码:
#include <iostream>
using namespace std;
int n,s,t,m;
int a[20001][20001];
int vis[20001];
int tempnumber=1e8,tempmax=-111111,tempminn;///暂时
int remnumber=1e8,remminn=1e8;;///实际
void dfs(int x)
{
if(tempminn-tempmax>remminn)///剪枝
return;
if(x==t)
{
if(tempminn-tempmax<remminn)
{
remminn=tempminn-tempmax;
remnumber=tempnumber;
}
else if(tempminn-tempmax==remminn&&tempnumber<remnumber)
{
remminn=tempminn-tempmax;
remnumber=tempnumber;
}
return;
}
for(int i=1;i<=n;i++)
{
if(!vis[i]&&a[x][i])
{
int temp1=tempmax,temp2=tempnumber;
vis[i]=1;
if(a[x][i]>tempmax)
{
tempmax=a[x][i];
tempnumber=x;
}
else if(a[x][i]==tempmax)
{
tempmax=a[x][i];
tempnumber=min(tempnumber,x);
}
tempminn+=a[x][i];
dfs(i);
vis[i]=0;
tempmax=temp1;
tempnumber=temp2;
tempminn-=a[x][i];
}
}
}
int main()
{
cin>>n>>s>>t>>m;///分别表示城堡数,起点s,终点t,道路数目
int q,b,c;
for(int i=0;i<m;i++)
{
cin>>q>>b>>c;
a[q][b]=a[b][q]=c;
}
vis[s]=1;
dfs(s);
cout<<remminn<<' '<<remnumber;
return 0;
}
202206201626一
边栏推荐
猜你喜欢
![Jerry's near end tone change problem of opening four channel call [chapter]](/img/03/f08cd660c1c602aa08218c4c791ec3.png)
Jerry's near end tone change problem of opening four channel call [chapter]

为了不曾忘却的纪念:孙剑专题
![[redis] three new data types](/img/ce/8a048bd36b21bfa562143dd2e47131.png)
[redis] three new data types
![List of outstanding talents: no crystal vibration, one drag, eight burn and upgrade [chapter]](/img/6c/333bc95fe390234d3d06043e4bded1.png)
List of outstanding talents: no crystal vibration, one drag, eight burn and upgrade [chapter]
How to operate redis on the IntelliJ idea database console

TC397 Flash

数据库总结:mysql在开发过程中常见的问题及优化

不同网络结构的特征也能进行对比学习?蚂蚁&美团&南大&阿里提出跨架构自监督视频表示学习方法CACL,性能SOTA!

第033讲:异常处理:你不可能总是对的2 | 课后测试题及答案

优化求解器 | Gurobi的MVar类:矩阵建模利器、求解对偶问题的备选方案 (附详细案例+代码)
随机推荐
分享insert into select遇到的死锁问题(项目实战)
校园跑腿管理端APP—陕西格创
Lesson 019: function: my site listen to my after-school test questions and answers
2022 group programming TIANTI race L1
Jerry's music mode obtains the directory of playing files [chapter]
第030讲:文件系统:介绍一个高大上的东西 | 课后测试题及答案
科研热点|官宣!2022年JCR分区和影响因子发布时间确定!
ACM. HJ45 名字的漂亮度 ●●
csv新增一列
84- I am on Internet & lt; 52 SQL statement performance optimization strategies & gt; Some views of
Analysis of fegin
TC397 Flash
第025讲:字典:当索引不好用时 | 课后测试题及答案
Arcgis中las点云数据抽稀
第021讲:函数:lambda表达式 | 课后测试题及答案
Operation of simulation test platform for 2022 Shandong safety officer C certificate test
PHP image making
Lesson 031: permanent storage: pickle a jar of delicious pickles | after class test questions and answers
Fegin的解析
Jerry's near end tone change problem of opening four channel call [chapter]