MIKU酱是个玩游戏氪金的人,游戏公司给她制定了新的规则,如果想从关卡i到关卡j,你需要交一些钱就可以了,但同时,MIKU酱的爸爸zjw很爱她,所以她可以每过一关就向她爸要一次钱,但她爸每次给他的钱是固定的,MIKU酱是个不会节省的女孩,哪怕每次多出来的钱,她也会拿去买肥宅快乐水,所以每次要的钱一定花完,因为MIKU酱不想挨骂,所以希望每次他爸给她的钱最少。
tips(到达第n关即通过,每到达一关一定能通过这关)

输入描述:

多组输入,每个样例第一行输入两个整数n,m(2<=n<=200,1<=m<=1000)表示关卡和规则的数量,接下来m行规则,每行输入x,y,w(w<=1000),表示从关卡x到y需要缴纳w的费用,保证题目有解,不会出现x=y的情况

输出描述:

输出一行,代表最少的钱
示例1

输入

复制

4 4
1 2 2
1 3 1
2 4 3
3 4 1

输出

复制

1

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define ll long long
#define P pair<int,int>
#define ph push_back
const int inf=0x3f3f3f3f;
int n,m,x,y,w;
const int N =;
int dis[N];
vector<P>ve[N];
void init(){
for(int i=;i<N;i++) {
dis[i]=inf;
ve[i].clear();
}
}
int bfs(int sta){
priority_queue<P,vector<P>,greater<P> >q;
dis[sta] =;
q.push(P(,sta));
while(!q.empty()){
P p =q.top();
q.pop();
int fi =p.first,se=p.second;//fi:最短路径上到se位置的题目答案
if(se==n) return fi;
for(int i=;i<ve[se].size();i++){
P pp=ve[se][i];
int ff=pp.first,ss=pp.second;
if(dis[ff]>max(ss,fi)){
dis[ff]=max(ss,fi);//变小了
q.push(P(dis[ff],ff));
}
}
}
return inf;
}
int main()
{
while(~scanf("%d%d",&n,&m)){
init();
for(int i=;i<m;i++){
scanf("%d%d%d",&x,&y,&w);
ve[x].ph(P(y,w));
}
int xx = bfs();
printf("%d\n",xx);
}
return ;
}

最新文章

  1. 【BZOJ】3993: [SDOI2015]星际战争
  2. 进程控制之exit函数
  3. linux下拷贝整个目录
  4. OREACLE 数据库建表 添加判断表是否存在 不存在则新建
  5. FileStream:The process cannot access the file because it is being used by another process
  6. Hosting WCF Service
  7. 有关各个版本的Visual Studio(VS)和SQL Server安装的顺序总结
  8. python多进程--------linux系统中python的os.fork()方法
  9. C++ namespace的作用
  10. 20165328 学习基础和C语言基础调查
  11. JAVA微信公众号网页开发 —— 用户授权获取openid
  12. latex中使用listings显示代码
  13. json 相关知识
  14. SqlServer和MySql允许脏读的实现方式,提高查询效率
  15. WINCRIS的使用
  16. Gradle sync failed: Read timed out
  17. boost编译
  18. 微软职位内部推荐-Senior Software Engineer II-Search
  19. Mysql -- 设置中国时区时间
  20. 解题报告:poj 3264 最基本的线段树

热门文章

  1. android 开发-spinner下拉框控件的实现
  2. SpringBoot | 第二十一章:异步开发之异步调用
  3. C#中接口的深入浅出【转】
  4. 《Head First 设计模式》之策略模式——鸭子行为
  5. css最佳实践(reset.css)
  6. 零基础逆向工程26_C++_03_Vector
  7. centos7.4 安装后的基本设置
  8. JS实现正则表达式
  9. yii:高级应用程序搭建数据库的详细流程
  10. IOS 拖拽事件(手势识别)