3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 39 Solved: 14
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100
Sample Output
共有5个路标,贝茜可以依次经过路标4,3,2,1到家
HINT
Source
题解:么么哒又是一道双倍经验水题= =(HansBug:还有话说这不是最短路模板题么= =)
按照惯例,我还是贴两个代码,我只笑笑不说话
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
VAR
i,j,k,l,m,n,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
p:point;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
end;
begin
readln(m,n);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,l);
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),-);
c[]:=;f:=;r:=;d[]:=;g[]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=-) or (c[p^.g]>(c[d[f]]+p^.w)) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;inc(f);
end;
writeln(c[n]);
readln;
end.
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
VAR
i,j,k,l,m,n,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
p:point;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
end;
begin
readln(m,n);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,l);
end;
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),-);
c[]:=;f:=;r:=;d[]:=;g[]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=-) or (c[p^.g]>(c[d[f]]+p^.w)) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;inc(f);
end;
writeln(c[n]);
readln;
end.
3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家的更多相关文章
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- Til the Cows Come Home(最短路)
Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- POJ2387 Til the Cows Come Home(SPFA + dijkstra + BallemFord 模板)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37662 Accepted ...
- POJ 2387 Til the Cows Come Home
题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K ...
- 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33015 Accepted ...
- POJ 2387 Til the Cows Come Home (最短路 dijkstra)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...
- BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Description 农夫 ...
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )
dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1 ...
- 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果
3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solv ...
随机推荐
- #图# #dijkstra# ----- OpenJudge 726:ROADS
OpenJudge 726:ROADS 总时间限制: 1000ms内存限制: 65536kB 描述 N cities named with numbers 1 ... N are connected ...
- jQuery html text val方法使用
jQuery html text val方法使用 <%@ page language="java" import="java.util.*" pageEn ...
- JWPlayer使用指南
http://support.jwplayer.com/customer/portal/articles/1499103-quickstart-reference <div id="m ...
- Bootstrap相关的网站
http://www.bootcss.com/ http://expo.bootcss.com/ http://www.webresourcesdepot.com/20-beautiful-resou ...
- doubango地址配置
转自:http://wiki.sip2sip.info/projects/sip2sip/wiki/SipDeviceConfiguration SIP Device Configuration Th ...
- EntityFramework 简单入个门
任何一个和数据相关的系统里,数据持久化都是一个不容忽视的问题. 一直以来,Java 平台出了很多 NB 的 ORM 框架,Hibernate.MyBatis等等..NET 平台上,ORM 框架这一块一 ...
- 二分查找 - vb.net
Module Module1 Sub Main() Dim array(999) As Integer Dim searchValue As Integer ...
- 使SSH不用输入密码
1. 自动ssh/scp方法== A为本地主机(即用于控制其他主机的机器) ;B为远程主机(即被控制的机器Server), 假如ip为192.168.60.110;A和B的系统都是Linux 在A上运 ...
- HDU1716(全排列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- [JavaScript] 学习笔记-JavaScript基础教程
1.JavaScript介绍 1)JavaScript是互联网上最流行的脚本语言,这门语言可用于Web和HTML,更可广泛用于服务器.pc端.移动端.JavaScript是一种轻量级的编程语言,插入H ...