HDU2544 最短路 2017-04-12 18:51 31人阅读 评论(0) 收藏
最短路
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 77 Accepted Submission(s) : 48
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
输入保证至少存在1条商店到赛场的路线。
Output
Sample Input
2 1
1 2 3
3 3
1 2 5
2 3 5
3 1 2
0 0
Sample Output
3
2
Source
UESTC 6th Programming Contest Online
———————————————————————————————————
最短路裸题,Dijkstra解决
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
#define inf 0x3f3f3f3f int dis[205];
int vis[205];
int mp[205][205];
int m,n; void djstl()
{
for(int i=1;i<=n;i++)
{
dis[i]=mp[1][i];
vis[i]=0;
}
dis[1]=0;
vis[1]=1;
for(int i=1;i<n;i++)
{
int mn=inf,u=-1;
for(int j=1;j<=n;j++)
{
if(dis[j]<mn&&vis[j]==0)
{
mn=dis[j];
u=j;
}
}
if(u!=-1)
{
dis[u]=mn;
vis[u]=1;
for(int j=1;j<=n;j++)
{
if(dis[u]+mp[u][j]<dis[j]&&vis[j]==0)
dis[j]=dis[u]+mp[u][j];
} }
}
if(dis[n]<inf)
printf("%d\n",dis[n]);
else
printf("-1\n");
} int main()
{
int u,v,c,st,ed;
while(~scanf("%d%d",&n,&m)&&(m||n))
{
memset(mp,inf,sizeof(mp));
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&c);
if(mp[u][v]>c)
mp[u][v]=mp[v][u]=c;
}
djstl();
}
}
HDU2544 最短路 2017-04-12 18:51 31人阅读 评论(0) 收藏的更多相关文章
- winform只允许一个应用程序运行 2014-12-08 09:51 31人阅读 评论(0) 收藏
使用互斥体Mutex类型 导入命名空间 using System.Threading; //声明互斥体 Mutex mutex = new Mutex(false, "ThisShouldO ...
- POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4998 Accepted: 1892 Desc ...
- Http,Https(SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2的配置和使用 分类: ASP.NET 2014-11-05 12:51 97人阅读 评论(0) 收藏
下载地址1:https://securityswitch.googlecode.com/files/SecuritySwitch%20v4.2.0.0%20-%20Binary.zip 下载地址2:h ...
- POJ3111 K Best 2017-05-11 18:12 31人阅读 评论(0) 收藏
K Best Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 10261 Accepted: 2644 Case Time ...
- hadoop调优之一:概述 分类: A1_HADOOP B3_LINUX 2015-03-13 20:51 395人阅读 评论(0) 收藏
hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
随机推荐
- CentOS7 防火墙配置-详解
CentOS 7 防火墙配置 1.防火墙的简述 防火墙对服务器起到一定的保护作用,所以了解一些相关的操作是很有必要的. 在CentOS 7.x中,有了一种新的防火墙策略叫FireWall , 在6.x ...
- 大型发布会现场的 Wi-Fi 应该如何搭建(密集人群部署wifi抗干扰)?
原文连接: http://www.zhihu.com/question/20890194 WiFi网络的部署要远远比一般人想象的复杂,不是说放上几十个AP带宽就自动增加几十倍,恰恰相反,简单放几十个A ...
- Fragment 横竖屏切换问题
转自:http://my.oschina.net/u/614511/blog/76444 在默认情况下当发生横竖屏切换时,当前Activity中的fragment都会通过Fragment.instan ...
- Linux操作系统多线程信号总结
linux 多线程信号编程总结 linux 多线程信号总结(一) 1. 在多线程环境下,产生的信号是传递给整个进程的,一般而言,所有线程都有机会收到这个信号,进程在收到信号的的线程上下文执行信号处理函 ...
- mac sublime切换编辑语言的方法(添加其他版本的python)
在sublime中指定python版本,操作如下: Sublime——tools——build system——new build system 把文件中的内容替换为 { "cmd" ...
- mysql 5.6.15升级到5.6.43
今天闲来无事,观察测试环境的zabbix服务器,发现内存泄漏严重,于是重启了,想起了前几天写的帖子发生了严重的内存泄漏可以把mysql升级到最新的小版本 于是乎就试着升级 old version:5. ...
- urllib2异常处理(七)
urllib2 的异常错误处理 在我们用urlopen或opener.open方法发出一个请求时,如果urlopen或opener.open不能处理这个response,就产生错误. 这里主要说的是U ...
- probably another instance of uWSGI is running on the same address (127.0.0.1:9090). bind(): Address already in use
probably another instance of uWSGI is running on the same address (127.0.0.1:9090). bind(): Address ...
- probably another instance of uWSGI is running on the same address
probably another instance of uWSGI is running on the same address 可以用命令杀掉这个端口在重启: /tcp
- 在WebBrowser中发送POST请求
我们要用到的也是WebBrowser的“Navigate”方法,其函数原型如下所示: Sub Navigate(URL As String, [Flags], [TargetFrameName], [ ...