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[ ...
随机推荐
- 配置Android环境遇到的问题及解决办法
配置Android环境遇到的问题及解决办法: 1 环境安装地址 http://pan.baidu.com/s/1jGzNzyI 2 其他: 2.1 安装 2.1.1 安装JDK,JRE 成功安装之后, ...
- Windows 2008修改密码策略方法
Windows Server 2008默认强制要求定期更改密码,这个功能有时实在是让人烦不胜烦,适当情况下可以考虑关闭. 方法如下: 1.按windows键+R(或者点开始---动行)打开运行窗口,输 ...
- hdu1171
use fmax().-------TLE #define mmax(a,b) (a)>(b)?(a):(b); ---796ms that's it! #include <stdio ...
- Android IOS WebRTC 音视频开发总结(三八)-- tx help
本文主要介绍帮一个程序员解决webrtc疑问的过程,文章来自博客园RTC.Blacker,支持原创,转载请说明出处(www.rtc.help) 这篇文章内容主要来自邮件,为什么我会特别整理到随笔里面来 ...
- 码农谷 求前N项之和
题目描述 有一分数序列:2/1.3/2.5/3.8/5.13/8.21/13.......求出这个数列的前N项之和,保留两位小数. 输入描述 N 输出描述 数列前N项和 样例 输入: 输出: 16.4 ...
- [系统]制作老毛桃U盘WinPE
准备工作,1G以上的U盘一个, Winpe 工具一个,个人推荐老毛桃winpe Ghost镜像文件(这个不用说了吧,能想到U盘装系统肯定都知道的) 可以开始了:插入U盘(最好把U盘里的东西清空,自己保 ...
- 在javascript中如何取消事件冒泡
如果在javascript中只希望事件发生在它的目标而不是在它的父元素上,即取消它的冒泡事件的发生,该如何做?因为按照javascript发生事件的顺序,它由两个阶段:分别从根元素--父元素--目标元 ...
- ios网络:应用一个请求的7个步骤
Splitting big tasks into small tasks is often one of the best ways to solve a problem. Thus, in the ...
- Windows Server 2008 R2 实现多用户连接远程桌面
前提 1. 确认自己的计算机开启了远程连接 2. 在远程桌面会话主机配置中将"限制每个用户只能进行一个会话"的勾去掉. 实现方法 1. 需要在角色里面安装远程桌面服务: 2. 在用 ...
- 开始安装 ASP.NET (4.0.30319.18408)。 出现了错误: 0x8007b799 必须具有此计算机的管理员权限才能运行此工具
在Visual Studio命令提示符安装ASP.NET .出现了错误: 0x8007b799 必须具有此计算机的管理员权限才能运行此工具:如下图: 解决方案如下: 1.打开“C:\Windows\S ...