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 ...
随机推荐
- TimeExit 界面无点击定时退出类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- java对象模型
java对象模型其实就是JVM中对象的内存布局.一个对象本身内在结构的描述信息以字节码的方式存储在方法区中(参见java内存区域),说白了就是class文件.那么如何获取到对象的class信息呢?虚拟 ...
- opensuse下配置IP、DNS、GATEWAY
本人物理主机IP描述 IPv4 地址 . . . . . . . . . . . . : 192.168.1.101(首选)子网掩码 . . . . . . . . . . . . : 255.25 ...
- 使用SharpZip压缩与解压缩
使用SharpZip压缩与解压缩 编写人:左丘文 2015-4-11 大家在做项目时,相信会经常性的会遇到要对数据流或dataset byte[] 或文件进行压缩和解压缩,比如:利用webservic ...
- bzoj1811 mea
Description 考虑一个非递减的整数序列 S1,....Sn+1(Si<=Si+1 1<=i<=n). 序列M1...Mn是定义在序列S的基础上,关系式为 Mi=( Si ...
- 保持一个会话 添加 HTTP Cookie管理器
在线程组中添加 http cookie manager即可 场景:登录后点击刷新简历
- 通过BeanFactoryPostProcessor来获取bean
一.现在我们很多时候都在spring的容器中,进行bean的提取和操作,但是配置里面首先需要扫描相应的包来实现相关bean的注入 但是问题来了.如果我们在另外一个线程需要用的时候,并且没有配置扫描该类 ...
- mysql java.sql.SQLException: Can't call commit when autocommit=true
java.sql.SQLException: Can't call commit when autocommit=true at com.mysql.jdbc.SQLError.createSQLEx ...
- 跟我学算法 - 读取excel文件(xlrd)
import xlrd import numpy as np # fname 表示文件名 fname = '1白.xlsx'# 打开文件 bk = xlrd.open_workbook(fname)# ...
- django多对多数据库建立 以及数据的传输 并进行增加 删除 修改
多对多数据库的建立 class Host(models.Model): nid = models.AutoField(primary_key=True) #自增id hostname = models ...