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[ ...
随机推荐
- c# winform 关于DataGridView的一些操作(很全,绝对够用)
转自:http://heisetoufa.iteye.com/blog/405317 设置字段名 设置字段值 设定单元格表示 Error图标 设定当前单元格 取得当前单元格内容 取得当前单元格的列 I ...
- SQL Server 之登录
1:SQL Server 是Microsoft 公司推出的关系型数据库管理系统. 安装好后,开始登录. 2:几种登录方式: (1):服务器名称: ①: . :代表本地服务器 ②: local :代表本 ...
- 实现在Android开发中的Splash Screen开场屏的效果
很多网友可能发现近期Tencent推出的手机QQ Android版包含了一个开场屏Splash Screen载入效果,通常游戏或大型软件打开时可能需要一个释放解析资源的过程,需要一个前台的动画播放和后 ...
- python centos上出现上下键和退格键均为乱码
出现此问题主要是由于未安装readline,可以使用python自带的readline,具体设置方式为: 1.cd /Python-2.7.9 (下载包后的路径)2../configure3.vim ...
- 添加删除程序无法安装IIS 提示没法加载模块
添加删除程序无法安装IIS 提示没法加载模块 安装iis的时候提示 解决办法:依次是 属性--高级--系统变量--Path 变量值是:%SystemRoot%\system32;%SystemRoo ...
- Copying Rowsets
I find that you often need to create and manipulate standalone rowsets. Sometimes you can get the da ...
- luigi学习5-task详解
task是代码执行的地方.task通过target互相依赖. 下面是一个典型的task的大纲视图. 一.Task.requires requires方法用来指定本task的依赖的其他task对象,依赖 ...
- 配置pxe 自动化安装centos6.7
dhcp服务器是pxe自动化安装的必要条件,因此先搞定dhcp服务器,yum -y install dhcp, rpm -ql dhcp查看安装了哪些包,less /etc/dhcp/dhcpd.c ...
- 关于PYTHON_EGG_CACHE无权限的问题
Perhaps your account does not have write access to this directory? You can change the cache director ...
- 图片加载与缓存利器(自动缓存)--第三方开源-- Glide
Android Glide使用便利,短短几行简单明晰的代码,即可完成大多数图片从网络(或者本地)加载.显示的功能需求. 使用Android Glide,需要先下载Android Glide的库,And ...