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 ...
随机推荐
- eclipse 的安装和汉化
第一步:直接百度搜索eclipse,第一个就是官方网站 第二步:点击DOWNLOAD 64BIT进入下载页面 第三步:点击DOWNLOAD进行下载 If the download doesn't st ...
- bzoj 3879: SvT
Description (我并不想告诉你题目名字是什么鬼) 有一个长度为n的仅包含小写字母的字符串S,下标范围为[1,n]. 现在有若干组询问,对于每一个询问,我们给出若干个后缀(以其在S中出现的起始 ...
- [转]oracle 12c 中的分页子句
转自:http://blog.itpub.net/271063/viewspace-1061279/ -- 连接数据库 创建测试用户-- Connected to Oracle Database 12 ...
- SmallLocks
folly/SmallLocks.h This module is currently x64 only. This header defines two very small mutex types ...
- 好记性比如烂笔头--linux学习笔记7关于linux中的shell脚本编程
之前看的各种面试,貌似都有shell脚本编程,没了解之前感觉很复杂,现在了解了些,没想象中那么难. 逻辑主要是这样的 编写.sh的脚本文件,文件里面的代码,就是在命令行输入的可执行命令的加强版,所谓加 ...
- 好记性不如烂笔头--linux学习笔记8关于nginx的动静分离
动静分离逻辑梳理 就是给nginx配置访问规则,不同后缀的文件访问不同的目录 worker_processes 1; events { worker_connections 1024; } http ...
- OpenCL 直方图
▶ 计算直方图,由原子计数和规约计算两部分组成 ● 最简单的版本,代码 // kernel.cl #pragma OPENCL EXTENSION cl_khr_local_int32_base_at ...
- Grapher - Change how graphs look
[Change how graphs look] Pan and zoom the graph 工具条如下: Change the type of graph 开场的Graph Template在Me ...
- Tomcat 用startup.bat启动,卡住解决
相比较用eclipse发布项目,直接在tomcat的bin目录下用startup.bat启动需要多做一些工作,而且直接运行startup.bat不会报错,不利于解决问题 所以最好的选择是在安装部署时 ...
- 77. Combinations (Recursion)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...