博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2387 Til the Cows Come Home (最短路+Dijkstra)
阅读量:6993 次
发布时间:2019-06-27

本文共 1812 字,大约阅读时间需要 6 分钟。

Til the Cows Come Home
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 29550   Accepted: 9935

Description

Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible.
Farmer John's field has N (2 <= N <= 1000) landmarks in it, uniquely numbered 1..N. Landmark 1 is the barn; the apple tree grove in which Bessie stands all day is landmark N. Cows travel in the field using T (1 <= T <= 2000) bidirectional cow-trails of various lengths between the landmarks. Bessie is not confident of her navigation ability, so she always stays on a trail from its start to its end once she starts it.
Given the trails between the landmarks, determine the minimum distance Bessie must walk to get back to the barn. It is guaranteed that some such route exists.

Input

* Line 1: Two integers: T and N
* Lines 2..T+1: Each line describes a trail as three space-separated integers. The first two integers are the landmarks between which the trail travels. The third integer is the length of the trail, range 1..100.

Output

* Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.

Sample Input

5 51 2 202 3 303 4 204 5 201 5 100

Sample Output

90

Hint

INPUT DETAILS:
There are five landmarks.
OUTPUT DETAILS:
Bessie can get home by following trails 4, 3, 2, and 1.

Source

题目大意:有N个点,给出从a点到b点的距离,当然a和b是互相能够抵达的,问从1到n的最短距离

解题思路:模版题,这题要注意的是有重边,dijkstra的算法须要考虑下,bellman-ford和spfa能够忽略这个问题

代码:实验证明这道题的数据临界值是1000,我开1000的dis[0]没用,就挂了。。。无语。

#include 
#include
#include
#include
using namespace std;#define M 1005#define INF 9999999#define min(a,b) (a

转载地址:http://ihivl.baihongyu.com/

你可能感兴趣的文章
shell脚本-----按行读取文件
查看>>
前端上传组件Plupload使用指南
查看>>
JS自动缩放页面图片
查看>>
DMZ
查看>>
org.xml.sax.SAXParseException; 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止
查看>>
weblogic学习笔记(一)----安装wls1213_dev_update2.zip
查看>>
HashMap的工作原理
查看>>
iOS 组件化实现的一些思路总结
查看>>
CoreText 入门(一)-文本绘制
查看>>
java那些事(四)之创建对象的四种方式
查看>>
stat命令输出结果中, Access,Modify,Change的含义
查看>>
POI封装一:导入 Import
查看>>
K星异客 K-PAX (2001)
查看>>
webservice通过soap协议出现不能加载wsdl文件解决办法
查看>>
创建Docker Hub账号&库
查看>>
linux配置实践:httpd+tomcat7+域名虚拟主机配置
查看>>
设计模式 之 策略模式
查看>>
快速排序算法(方式二)图解(窃)
查看>>
jdk7和8的一些新特性介绍
查看>>
面向对象设计
查看>>