最短路

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

在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?


Input

输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路。N=M=0表示输入结束。接下来M行,每行包括3个整数A,B,C(1<=A,B<=N,1<=C<=1000),表示在路口A与路口B之间有一条路,我们的工作人员需要C分钟的时间走过这条路。

输入保证至少存在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) 收藏的更多相关文章

  1. winform只允许一个应用程序运行 2014-12-08 09:51 31人阅读 评论(0) 收藏

    使用互斥体Mutex类型 导入命名空间 using System.Threading; //声明互斥体 Mutex mutex = new Mutex(false, "ThisShouldO ...

  2. POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏

    Cow Acrobats Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4998   Accepted: 1892 Desc ...

  3. 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 ...

  4. 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 ...

  5. hadoop调优之一:概述 分类: A1_HADOOP B3_LINUX 2015-03-13 20:51 395人阅读 评论(0) 收藏

    hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...

  6. 移植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 ...

  7. Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏

    全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...

  8. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  9. 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 ...

随机推荐

  1. GNU Radio: Synchronization and MIMO Capability with USRP Devices

    Application Note Synchronization and MIMO Capability with USRP Devices Ettus Research Introduction S ...

  2. 转:HL7 Tools suite

    HL7 Tools suite   HL7的官网有很多开源工具, 比如:RoseTree,V3Generator,RMIM Designer, Design Repository, V2 & ...

  3. SpringIoc 和 工厂模式(反射实现)

    一.先演示 “简单工厂”: package org; interface Fruit { public void eat(); } class Apple implements Fruit { pub ...

  4. JavaWeb的过滤器Filter

    Filter的作用是在请求到达web资源(HTML.css.Servlet.Jsp)之前拦截,做一个预处理. 创建一个类实现Filter接口,在web.xml中对文件进行配置 <filter&g ...

  5. Android网络请求

    HTTP请求与响应 HTTP请求包结构 例: POST /meme.php/home/user/login HTTP/1.1 Host: 114.215.86.90 Cache-Control: no ...

  6. 马士兵Spring-dataSource

    一.简单使用例子: 这里使用commons.dbcp: beanx.xml配置: <?xml version="1.0" encoding="UTF-8" ...

  7. charles 小米手机安装Charles证书

    1.手机Wi-Fi设置手动代理,添加IP和端口号 此处是:192.168.63.143:8888, 2.保存证书,PC端访问 chls.pro/ssl 下载pem证书,发送到手机 adb push c ...

  8. centos7.3给squid搭建代理服务器添加认证nginx

    1先安装 nginx 这里是教程 点击查看 2 然后 使用命令 创建用户 htpasswd -c /etc/nginx/passwd.db baker 输入密码  提示添加完毕 3 查看加密后的用户和 ...

  9. 好记性不如烂笔头--linux学习笔记9练手写个shell脚本

    #!/bin/bash #auto make install httpd #by authors baker95935 #httpd define path variable H_FILES=http ...

  10. 使用http-proxy-middleware 代理跨域

    使用http-proxy-middleware 代理跨域 例如请求的url:“http://f.apiplus.cn/bj11x5.json” 1.打开config/index.js,在proxyTa ...