Til the Cows Come Home

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

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Til the Cows Come Home
DescriptionnnBessie 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. nnFarmer 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. nnGiven 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.nInputnn* Line 1: Two integers: T and N nn* 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.nOutputnn* Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.nSample Inputnn5 5n1 2 20n2 3 30n3 4 20n4 5 20n1 5 100nSample Outputnn90nHintnnINPUT DETAILS: nnThere are five landmarks. nnOUTPUT DETAILS: nnBessie can get home by following trails 4, 3, 2, and 1.
畅通工程续 + Til the Cows Come Home(最短路)
【板子】 板子要理解,要熟练。 https://blog.csdn.net/qq_41117236/article/details/80517605 【一】 畅通工程续 TimeLimit:1000MS  MemoryLimit:32768KB 64-bit integer IO format:%I64d Problem Description 某省自从实行了很多年的畅通工程计划后...
Til the Cows Come Home (最短路问题, 模板)
题目:https://vjudge.net/problem/POJ-2387  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 nee...
【最短路】Til The Cows Come home(裸题)
参考:https://blog.csdn.net/major_zhang/article/details/72519233自己写的简单Dijkstra:#include &amp;lt;stdio.h&amp;gt; #include &amp;lt;algorithm&amp;gt; #include &amp;lt;vector&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;string.h&amp;...
Til the Cows Come Home (有向图最短路径问题)
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M≤ 100,000) unidirectional (one-way roa...
Til the Cows Come Home (求图中的最短路)
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 slee...
Til the Cows Come Home(最短路算法母题)
原题链接 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45313 Accepted: 15372 DescriptionBessie is out in the field and wants to get back to the barn to g
最短路和差分约束(三种算法实现)( Til the Cows Come Home )
题目训练链接(密码hpuacm): https://vjudge.net/contest/246705 我会分别用 迪杰斯特拉  优先队列和链式前向星优化过的迪杰斯特拉  SPFA算法 三种方法讲一下例题。 此外上述三种算法是求单源最短路问题, 这里还会介绍一下多源最短路的算法 floyd算法。多源最短路可以求出任意两点间的最短距离。 在存图方式中会用到邻接矩阵 链式前向星等存图方式,不知道...
Til the Cows Come Home(最短路,注意重边)
题目链接:http://poj.org/problem?id=2387   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....
Til the Cows Come Home (最短路矩阵存图去重边)
Til the Cows Come Home  POJ - 2387    #include&amp;lt;iostream&amp;gt; #include&amp;lt;cstring&amp;gt; using namespace std; const int maxn=2005; #define inf 0x3f3f3f3f int a[maxn][maxn]; int m,n; int dis[maxn]; i...
POJ 2387 Til the Cows Come Home(迪杰斯特拉/优先队列/最短路)
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18265 代码: #include #include #include using namespace std; const int maxn=2005; vector >E[maxn]; int d[maxn]; int n,m; void init() {
最短路模板问题:Til the Cows Come Home【最短路】
Til the Cows Come Home  POJ - 2387  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 h...
(Til the Cows Come Home )链式前向星存图,优先队列,dijkstra算法
题目链接  USACO 2004 November 下面只是介绍模板,对于这道题还要注意边和顶点的输入顺序,下面的模板都是按照先顶点后边的顺序处理的,直接复制 提交会wa的,所以最好是自己理解着做,要是偷懒直接复制wa了别怪我 常规易于理解的方法 #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;queue&amp;gt; #include &amp;lt;string.h&amp;...
POJ 2387 Til the Cows Come Home(图论几个基本算法的初探)
Til the Cows Come HomeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 65500 Accepted: 22064DescriptionBessie is out in the field and wants to get back to the barn to get as much sleep as pos...
POJ 2387 Til the Cows Come Home (最短路径 模版题 三种解法)
原题链接:Til the Cows Come Home 题目大意:有  个点,给出从  点到  点的距离并且  和  是互相可以抵达的,问从  到  的最短距离。   题目分析:这是一道典型的最短路径模版题,需要注意的是:使用dijkstra算法求解需要考虑有重复边问题,而使用bellman-ford算法 和 spfa算法 可以忽略这个问题。 代码如下: // Dijkstra #in...
百练 / 2017研究生推免上机考试 H: Til the Cows Come Home
题目来源:http://poj.org/problem?id=2387----------------------------------------Til the Cows Come Home总时间限制: 1000ms     内存限制: 65536kB描述Bessie is out in the field and wants to get back to thebarn to get as ...
Bessie Come Home 回家(最短路)
Description 现在是晚餐时间,而母牛们在外面分散的牧场中。 农民约翰按响了电铃,所以她们开始向谷仓走去。 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只速度最快的母牛)。 在挤奶的时候(晚餐前),每只母牛都在她自己的牧场上,一些牧场上可能没有母牛。 每个牧场由一条条道路和一个或多个牧场连接(可能包括自己)。 有时,两个牧场(可能是自我相同的)之间会有超过一...
Come in!!Come in!!Come in!!Come in!!
请问VB中的RTF格式为何物?这种格式的文本如何编写,编写的过程中各符号是如何约定的?在哪儿能得到有关RTF的资料或知识??????
洛谷P1529 回家 Bessie Come Home【最短路径】
题目描述 https://www.luogu.org/problemnew/show/P1529 把字母转换成数字后,求离Z点最近的奶牛,近似模板题。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; using namespace std; int mp[60][60],p; int main() ...
USACO2.4.4 Bessie Come Home 回家 解题报告(模拟)
Description 现在是晚餐时间,而母牛们在外面分散的牧场中。 农民约翰按响了电铃,所以她们开始向谷仓走去。 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只速度最快的母牛)。 在挤奶的时候(晚餐前),每只母牛都在她自己的牧场上,一些牧场上可能没有母牛。 每个牧场由一条条道路和一个或多个牧场连接(可能包括自己)。 有时,两个牧场(可能是自我相同的)之间会有超过一...
【最短路径】洛谷 P1529 回家 Bessie Come Home
题目描述现在是晚餐时间,而母牛们在外面分散的牧场中。 农民约翰按响了电铃,所以她们开始向谷仓走去。 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只最快的母牛)。 在挤奶的时候(晚餐前),每只母牛都在她自己的牧场上,一些牧场上可能没有母牛。 每个牧场由一条条道路和一个或多个牧场连接(可能包括自己)。 有时,两个牧场(可能是字母相同的)之间会有超过一条道路相连。 至少有一个
come!come!come here!
有几个问题:rn1、DREAMWEAVER中的字体能改默认的值吗?好比说我一打开它字体就可以是5号!rn2、有做过留言板的吗?提供一下思路或者说那里有下的也行!如果留言板坏了能把信息直接发到信箱吗?rn3、有用DREAMWEAVER MX中的功能做过登录的吗?我怎么做老出问题,做不成啊!?rn
come in come in
C语言:输入一行字符,分别统计出其中英文字母、空格、数字、和其他字符的个数。rn要求:尽量少用或不用等头文件包涵的函数。rn////////////////////////////////////////////////////////////////rn#include rn#include rnrnvoid main()rnrn char c;rn int A_num=0,a_num=0,space=0,num=0,others=0;rnrn while((c=getchar())!='\n')rn rn if (isupper(c)) A_num++;rn else if (islower(c)) a_num++;rn else if (isdigit(c)) num++;rn else if (isspace(c)) space++;rn else others++;rn rn printf("\这一行文字中:\n大写字母有%d个",A_num);rn printf("\n小写字母有%d个",a_num);rn printf("\n空格有%d个",space);rn printf("\n数字有%d个",num);rn printf("\n其它字符有%d个\n",others);rnrn/////////////////////////////////////////////////////////////////rn以上的代码使用了isupper,islower,isdigit,isspace四个函数。我的意思是避免使用诸如此类的函数。rn
come come come,a q.
来来来,一个问题:rn[code=C/C++]struct _FILE_INFO_TYPE_rnrn INT8U a_type:2; rn INT8U b_type:3; rn INT8U is_c:1; rn INT8U is_d:1; rn INT8U is_e:1; rn ;rnrnstruct _FILE_INFO_rnrn struct _FILE_INFO_TYPE_ pfile_info_type;rn INT8U a_name_len; rn char *a_name;rn char *b_name;rn char *c_name;rn char *d_name;rn char *e_name;rn struct _FILE_INFO_ *next;rn; rnrnINT8U Init_Info(void)rnrn struct _FILE_INFO_ *add; rnrn add = (struct _FILE_INFO_ *)AVMem_umalloc(sizeof(struct _FILE_INFO_));rn if(add == NULL)rn rn printf("malloc error!\n");rn return 0;rn rn add->a_name = (char *)AVMem_umalloc(16);rn rn if(!add->a_name)rn rn AVMem_free(add);rn return 0;rn rn rn sprintf(add->a_name,"%s","this is a demo.");rn rn add->next = NULL;rn....rnrnrn[/code]rnrn这样写哪里不对,感觉不对,但说不上来。。你呢?
TIL传输中过期
最开始是连不上测试的数据库,然后用在cmd界面ping数据库的地址ping不通,出现这个报错,一开始按照网上思路,使用ipconfig/flushcdn清除缓存,但是没有用效果。 后来发现其实是自己的电脑跟开发库不是在一个网段里面,于是在tcp4里面再设置一个跟开发库同一个网段的ip即可 ...
come on
hello everybody :)rr===========================================================r★CSDN助手.Net★rr功能简介:r1、真正离线浏览,智能缓存,自动更新本地数据库,也能一次性下载论坛所有帖子,速度飞快。r2、强大的搜索功能,能进行“标题”,“全文”及“作者”关键字搜索。r3、帖子更新自动监测提醒(在线等待的时候不用不停的刷新帖子了)。r4、分类收藏夹,可以非常方便的进行精华帖子本地典藏。r5、可以选择保存用户名和密码,自动登录。r6、方便的发贴和回复(可以群发)。r7、自由设计个性签名。r8、帖子内的Web连接自动探测,点击直接打开外部浏览器。r9、可以自由设置帖子查看区的字体,颜色,背景。r10、个人专区(我的帖子列表,我参与的帖子列表)。rr下载地址:http://www25.brinkster.com/nluyan/csdn.zip
CoME iN!
我总感觉是不是学习JSP,更多接触的是ORACLE数据库而不是SQLrnrn这观点对吗?两种数据库的优势在哪呢,JSP(或服务器)更多是用的哪种?!
come in
L—>length=listsizern—>是什么意思/rn谢谢各位rn
come
rt
come on!
how to list all of the files and folders under the special directory?
Come in
J2ME技术讨论QQ群rnrnNUM:9978239rnrn欢迎加入!
come in !!
本人从事2年的嵌入式手机开发,开发过单机游戏无数,开发过手机电话本之类的工具,短信平台工具等等rn从事1年的防火墙开发,主要是硬件firewall,对网络协议有深刻的理解。rn现从事无线局域网驱动和应用的开发。rn多年的C、C++开发经验,VC++开发过多个实用工具,现有多余时间想兼职,有项目或是想合作的请联系rnQQ:76863599rnMSN:xqxxlbetter@hotmail.com
Come!Come!In!In!(查询)
各路英雄:rn我在制作SQL的模糊查询时,遇到一个问题,百思不得其解!rn with Query2 dorn beginrn close;rn parambyname('value').asstring :='%'+edit1.Text+'%';rn prepare;rn open;rn end;rn第一次查询没问题,一但执行其他的操作后,回过头来再查询,系统提示rnQuery2: parameter'value' not foundrn不知为何故!
come come给我指导!
我的英语目前是四级水平,我是先过六级还是学习计算机专业英语?rn一名优绣程序员的数学水评应该有多高?
Come In
http://go8.163.com/dbcontrols/最新VB免费控件38个
come in!!!
两个整数相除要取的小数点应该怎么做了rn 比喻rn i=10;rn j=3rn i/j=3.333333
Come!Come!Come!In!In!In!(让我们改变字段)
用Database DeskTop的ParaDox7定义了一个L型的字段Yijie;rn由UpdateSQL1的ModifySQL定义。rn update "Book.DB"rn setrn Yijie = :Yijiern wherern Suoshuhao = :OLD_Suoshuhao(Suoshuhao是主索引字段)rn同时在一个Button事件中,编辑如下:rn if Query2.FieldByName('Yijie').AsBoolean thenrn ShowMessage('该书已经借出!')rn elsern beginrn Query2.Edit;rn Query2.FieldByName('Yijie').AsBoolean:= True;rn Query2.ApplyUpdates;rn end;rn但每次一按确定,他提示我query2:cannot modified a read-only datasetrnrn不知为什么?
come!
vc++6.0还能坚持多久?rnvc++6.0是否能完全用于windowspx?rn
come in!
我培训时学的是JAVA(自我感觉学的不错),可是工作后一直在做C#,VBA,当然工作大半年以来,C#编程不是问题,但是根本不精通,只能说知道逻辑就能编程吧rn由于本人在日企工作,想跳到欧美企业,不知道现在时从事JAVA好,还是C#好,请达人给点建议,谢谢!
Come in!!
不用数据库,本人还未学;rn只用java编程知识,怎么实现[b]多条件[/b]查找比较好~~rn条件是类里面的成员变量,也就是按多条件找符合的对象~~~
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数