AC代码
POJ2387 Til the Cows Come Home
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 5
1 2 20
2 3 30
3 4 20
4 5 20
1 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.

 
模板题吧,理解了dijkstra之后就ac了,留个坑,等刷完专题再整理一遍概念吧(或许整理不出)
然后现在才写最短路又被嫌菜了,,害,,

POJ2387 Til the Cows Come Home (最短路 dijkstra)的更多相关文章

  1. Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化)

    Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化) 贝西在田里,想在农夫约翰叫醒她早上挤奶之前回到谷仓尽可能多地睡一觉.贝西需要她的美梦,所以她想尽快回 ...

  2. POJ-2387 Til the Cows Come Home ( 最短路 )

    题目链接: http://poj.org/problem?id=2387 Description Bessie is out in the field and wants to get back to ...

  3. POj2387——Til the Cows Come Home——————【最短路】

    A - Til the Cows Come Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & ...

  4. POJ2387 Til the Cows Come Home(SPFA + dijkstra + BallemFord 模板)

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

  5. (Dijkstra) POJ2387 Til the Cows Come Home

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

  6. 【POJ - 2387】Til the Cows Come Home(最短路径 Dijkstra算法)

    Til the Cows Come Home 大奶牛很热爱加班,他和朋友在凌晨一点吃完海底捞后又一个人回公司加班,为了多加班他希望可以找最短的距离回到公司.深圳市里有N个(2 <= N < ...

  7. poj2387 Til the Cows Come Home 最短路径dijkstra算法

    Description Bessie is out in the field and wants to get back to the barn to get as much sleep as pos ...

  8. poj2387 Til the Cows Come Home

    解题思路:最短路的模板题,注意一个细节处理即可. 见代码: #include<cstdio> #include<cstring> #include<algorithm&g ...

  9. POJ2387 Til the Cows Come Home 【Dijkstra】

    题目链接:http://poj.org/problem?id=2387 题目大意; 题意:给出两个整数T,N,然后输入一些点直接的距离,求N和1之间的最短距离.. 思路:dijkstra求单源最短路, ...

随机推荐

  1. jquery设置css属性几种方式

    用css()方法返回元素的样式属性 $("div").css("padding-left")); 用css()设置样式 $("div").c ...

  2. Ueditor 从word中复制内容带多张图片

    粘贴文本 注意,以下配置暂时对 IE 无效.IE 暂时使用系统自带的粘贴功能,没有样式过滤! 关闭粘贴样式的过滤 当从其他网页复制文本内容粘贴到编辑器中,编辑器会默认过滤掉复制文本中自带的样式,目的是 ...

  3. python解析字体反爬

    爬取一些网站的信息时,偶尔会碰到这样一种情况:网页浏览显示是正常的,用python爬取下来是乱码,F12用开发者模式查看网页源代码也是乱码.这种一般是网站设置了字体反爬 一.58同城 用谷歌浏览器打开 ...

  4. Python3学习笔记(十五):常用时间模块time和datetime

    一.time模块 1.时间戳 time.time() :从1970-01-01到至今的秒数 import time print(time.time()) 1529238004.2784646 2.等待 ...

  5. 「CQOI 2014」危桥

    题目链接 戳我 \(Solution\) 首先往返\(n\)次等价于走\(2n\)次. 将 \(a_n*2,b_n*2\); 那么我们直接按原图构图,然后: \((S,a_1,a_n),(S,b_1, ...

  6. httpclient+jsoup实现网页信息抓取

    需求分析:抓取:http://tools.2345.com/rili.htm中的万年历(阳历.阴历等等). 1.首先为抓取的内容创建一个类.实现封装. package com.wan.domain; ...

  7. 小程序踩坑之获取不到e.target.dataset的值

    在页面与js传值中我们经常用到data-id="1"的方式,然后通过e.target.dataset.id取id的值今天在获取值时怎么也取不到,后来发现e对象有currentTar ...

  8. 使用FFmpeg让mp4转gif

    配好环境之后,需要在开始菜单中打开命令提示符,然后进入到test.mp4的文件目录下执行命令.(直接在文件目录下打开cmd不能生效)ffmpeg -i test.mp4 -f gif test.gif

  9. Scala学习(二)——高级特性

    apply() 方法 apply方法是Scala提供的一个语法糖 类名+括号,调用对象的apply方法 对象名+括号,调用类的apply方法 对apply方法的简单测试:(其中,带 new -- cl ...

  10. laravel 使用不同账号发送邮件的问题

    业务背景: 公司自己做的oa系统,不同的模块需要用不同的邮箱发送信息给收件人.比如:员工离职的时候用离职的邮箱发送离职邮件通知,员工入职的时候用入职的邮箱发送入职邮件通知.发邮件是一件耗时的任务,如果 ...