P3408: [Usaco2009 Oct]Heat Wave 热浪
水题,裸的最短路。
const maxn=;
type
link=^node;
node=record
t,d:longint;
f:link;
end;
var n,m,s,i,j,u,v,w,max:longint;
adj:array[..] of link;
f:array[..] of longint;
d,val:array[..] of longint;
went:array[..] of boolean;
procedure insert(f,t,d:longint);
var p:link;
begin
new(p);
p^.f:=adj[f];
p^.t:=t;
p^.d:=d;
adj[f]:=p;
end;
procedure spfa(s:longint);
var l,r,now,i:longint;
p:link;
begin
for i:= to n do
d[i]:=maxn;
fillchar(went,sizeof(went),true);
l:=; r:=; f[]:=s; d[s]:=; went[s]:=false;
while l<=r do
begin
now:=f[l];
p:=adj[now];
while p<>nil do
begin
if d[p^.t]>d[now]+p^.d then
begin
d[p^.t]:=d[now]+p^.d;
if went[p^.t] then
begin
went[p^.t]:=false;
inc(r);
f[r]:=p^.t;
end;
end;
p:=p^.f;
end;
went[now]:=true;
inc(l);
end;
end;
begin
readln(n,m,s);
for i:= to m do
begin
readln(u,v,w);
insert(u,v,w);
//insert(v,u,w);
end;
for i:= to n do
if i<>s then
begin
spfa(i);
val[i]:=d[s];
end;
spfa(s);
for i:= to n do
if i<>s then
begin
inc(val[i],d[i]);
if val[i]>max then max:=val[i];
end;
writeln(max);
end.
(转载请注明出处:http://www.cnblogs.com/Kalenda/)
P3408: [Usaco2009 Oct]Heat Wave 热浪的更多相关文章
- BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )
普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ ...
- 3408: [Usaco2009 Oct]Heat Wave 热浪
3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 67 Solved: 55[Subm ...
- [Usaco2009 Oct]Heat Wave 热浪(裸最短路径)
链接:https://ac.nowcoder.com/acm/contest/1082/F来源:牛客网 题目描述 The good folks in Texas are having a heatwa ...
- BZOJ3408: [Usaco2009 Oct]Heat Wave 热浪
最短路模板.选迪杰. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<alg ...
- 洛谷—— P1339 [USACO09OCT]热浪Heat Wave
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...
- Luogu P1339 热浪Heat Wave
Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...
- BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题( dp )
01背包... ----------------------------------------------------------------------- #include<cstdio&g ...
- 3406: [Usaco2009 Oct]Invasion of the Milkweed 乳草的入侵
3406: [Usaco2009 Oct]Invasion of the Milkweed 乳草的入侵 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 8 ...
- 3409: [Usaco2009 Oct]Barn Echoes 牛棚回声
3409: [Usaco2009 Oct]Barn Echoes 牛棚回声 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 57 Solved: 47[ ...
随机推荐
- HTML你应该知道的三大基本元素
顶级.块级.内联,html元素的三大分类 如果将这些元素细分, 又可以分别归为顶级(top-level)元素,块级(block-level)元素和内联(inline)元素. 1. Top-level ...
- WP8__从windowsphone app store 中根据app id获取应用的相关信息(下载网址及图片id等)
windows phone 官网应用商店地址 http://www.windowsphone.com/zh-cn/store/featured-apps------------------------ ...
- 实现MySQL的Replication
实现MySQL的Replication 实现MySQL的Replication在MySQL 3.23.15版本之后,MySQL提供了数据库复制的功能,可以实现两个数据库实时同步,增强了MySQ ...
- Oracle 中 根据值 查询 所在 表和字段
-------------------- -- 这里是查询 数字型字段值 /*declare CURSOR cur_query IS select table_name, column_name, d ...
- Windows USN Journal Parsing
What is "USN Journal"? It is "Update Sequence Number Journal". It records change ...
- css3为图片添加鼠标移入放大效果
只需要为添加效果的图片定义一个伪类 img.zoom-img:hover { -webkit-transform: scale(1.15); -webkit-transition-timing-fun ...
- javaSE第二十五天
第二十五天 399 1:如何让Netbeans的东西Eclipse能访问. 399 2:GUI(了解) 399 (1)用户图形界面 399 (2)两个包: 399 (3) ...
- ADO访问Access数据库错误解决心得随笔
最近在用ADO访问Access数据库的时候出现了一个奇怪的错误,觉得有必要记录下来,和大家分享一下. 环境 win7 x86系统: VS2012编译器: Office2010: Access2000~ ...
- C#winform设置DateTimePicker的时间格式
在对DateTimePicker进行时间格式设置时候,要先对属性Format设置为"Custom"自定义格式,然后再CustomFormat里面进行格式设置 比如"yyy ...
- php中iconv函数使用方法
最近在做一个程序,需要用到iconv函数把抓取来过的utf-8编码的页面转成gb2312, 发现只有用iconv函数把抓取过来的数据一转码数据就会无缘无故的少一些. iconv函数库能够完成各种字符集 ...