Hdu1874 畅通工程续 2017-04-12 18:37 48人阅读 评论(0) 收藏
畅通工程续
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 88 Accepted Submission(s) : 48
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。
Input
每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。
接下来是M行道路信息。每一行有三个整数A,B,X(0<=A,B<N,A!=B,0<X<10000),表示城镇A和城镇B之间有一条长度为X的双向道路。
再接下一行有两个整数S,T(0<=S,T<N),分别代表起点和终点。
Output
Sample Input
3 3
0 1 1
0 2 3
1 2 1
0 2
3 1
0 1 1
1 2
Sample Output
2
-1
Author
Source
#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(int st,int ed)
{
for(int i=0;i<n;i++)
{
dis[i]=mp[st][i];
vis[i]=0;
}
dis[st]=0;
vis[st]=1;
for(int i=1;i<n;i++)
{
int mn=inf,u=-1;
for(int j=0;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=0;j<n;j++)
{
if(dis[u]+mp[u][j]<dis[j]&&vis[j]==0)
dis[j]=dis[u]+mp[u][j];
} }
}
if(dis[ed]<inf)
printf("%d\n",dis[ed]);
else
printf("-1\n");
} int main()
{
int u,v,c,st,ed;
while(~scanf("%d%d",&n,&m))
{
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;
}
scanf("%d%d",&st,&ed);
djstl(st,ed);
}
}
Hdu1874 畅通工程续 2017-04-12 18:37 48人阅读 评论(0) 收藏的更多相关文章
- HDU1875 畅通工程再续 2017-04-12 19:52 48人阅读 评论(0) 收藏
畅通工程再续 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- Hdu1429 胜利大逃亡(续) 2017-01-20 18:33 53人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- 移植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 ...
- OpenCV与QT联合编译 分类: Eye_Detection ZedBoard OpenCV shell ubuntu 2014-11-08 18:54 143人阅读 评论(0) 收藏
问题1:首先参考rainysky的博客,发现qmake时发生找不到目录,文件的错误,又找不到 qmake.conf 文件的写法.所以开始按照网上的程序修改 XXX.pro 文件. 问题2:使用QT C ...
- 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 ...
- Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏
Doubles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19954 Accepted: 11536 Descrip ...
- OC基础:数组.字典.集 分类: ios学习 OC 2015-06-18 18:58 47人阅读 评论(0) 收藏
==============NSArray(不可变数组)=========== NSArray,继承自NSObject 用来管理(储存)一些有序的对象,不可变数组. 创建一个空数组 NSArray ...
随机推荐
- C++ Primer第五版答案
Downloads Download the source files for GCC 4.7.0. Download the source code files for MS Visual Stud ...
- 【linux】head&&tail
命令: head[-n][文件名] tail[-n][-f][文件名] 形式: -n 行数 (显示前几行) ...
- MySql-5.7.17 -winx64的安装配置
一.下载软件 1. 进入mysql官网,登陆自己的Oracle账号(没有账号的自己注册一个),下载Mysql-5.7.17,下载地址:http://dev.mysql.com/downloads/my ...
- sqlplus rlwrap readline
- 一次点击两次触发addEventListener
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MyBait 符号大于 小于理解
EQ 就是 EQUAL等于 NQ 就是 NOT EQUAL不等于 GT 就是 GREATER THAN大于 LT 就是 LESS THAN小于 GE 就是 GREATER THAN OR EQUAL ...
- Java里的堆(heap)栈(stack)和方法区(method)
基础数据类型直接在栈空间分配, 方法的形式参数,直接在栈空间分配,当方法调用完成后从栈空间回收. 引用数据类型,需要用new来创建,既在栈空间分配一个地址空间,又在堆空间分配对象的类变量 . 方法 ...
- 实现socketChannel 通信例子
https://blog.csdn.net/qq_33935895/article/details/79678345
- js常用代码整理
引用js <script type="text/javascript" src="js/jquery-1.11.2.min.js"></scr ...
- 什么是Emit,什么是反射,二者区别到底是什么?(转)
Emit的准确定义,我们看看微软给出的答案 System.Reflection.Emit 命名空间包含{ 允许编译器或工具发出元数据和发出 Microsoft 中间语言 (MSIL) ,并可选择在磁盘 ...