题目链接:

https://vjudge.net/contest/255738#problem/B

AC代码:

#include <iostream>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<stdio.h>
#define maxn 2000+10
using namespace std;
#define inf 0x3f3f3f3f
int n,m;
vector<pair<int,int > >q[maxn];
int vis[maxn];
int path[maxn];
int spfa()
{
for(int i=1; i<=n; i++)
{
vis[i]=0;
path[i]=0;
}
path[1]=inf;
vis[1]=1;
queue<int>w;
w.push(1);
int maxx=0;
while(!w.empty())
{
int top=w.front();
w.pop();
vis[top]=0;
maxx=max(maxx,path[n]);
if(path[top]<maxx)continue;
int len=q[top].size();
for(int i=0; i<len; i++)
{
int temp=q[top][i].first;
if(path[temp]<=path[top])
if(path[temp]<min(path[top],q[top][i].second)){
path[temp]=min(path[top],q[top][i].second);
if(path[temp]>maxx&&vis[temp]==0)
w.push(temp),vis[temp]=1;
}
}
}
return maxx;
}
int main()
{
int T;
int num=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
// cin>>n>>m;
for(int i=1; i<=n; i++)q[i].clear();
for(int i=1; i<=m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
q[u].push_back(make_pair(v,w));
q[v].push_back(make_pair(u,w));
}
int ans=spfa();
printf("Scenario #%d:\n",++num);
printf("%d\n",ans);
printf("\n");
// cout<<"Scenario #"<<++num<<":"<<endl<<ans<<endl;
}
return 0;
}

最新文章

  1. 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法
  2. linux创建用户、设置密码、修改用户、删除用户
  3. Windows平台下ActiveMQ 安装
  4. js严格模式“use strict”
  5. ubuntu12.04安装mysql
  6. 关于SQL中的Update语句
  7. HDU 1561 树形DP(入门)
  8. powershell学习
  9. HDU-4115 Eliminate the Conflict 2sat
  10. (转) xcodebuild和xcrun自动化编译ipa包 笔记
  11. 模块化定义JS,让统一文件夹内相同的变量不冲突
  12. Swift与Objective-C API的交互
  13. 开发者需要了解的WebKit
  14. System Rules 更好的测试
  15. timesten报错:error while loading shared libraries: libaio.so.1: cannot open shared object file : No such file or directory
  16. linux 服务器时间同步
  17. Java并发编程的艺术&#183; 笔记(1)
  18. Rhino学习教程——1.4
  19. 用java开发dota英雄最华丽的技能
  20. 避免jquery的click多次绑定方法

热门文章

  1. 基于SSH框架的学生选课质量属性分析
  2. Alpha答辩总结
  3. XCODE 6.1.1 配置GLFW
  4. 虚拟主机修改上传配置(PHP)
  5. Linux用户管理简介
  6. LVS(Linus Virtual Server):三种负载均衡方式比较+另三种负载均衡方式
  7. blog 社会化评论插件 多说for china, disqus for global range
  8. SpringMvc+JavaConfig+Idea 基于JavaConfig搭建项目
  9. Gym - 101522H Hit!
  10. gitlab 7.10.4 去除邮件认证