bzoj1752 [Usaco2005 qua]Til the Cows Come Home
Description
<= 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
Output
Sample Input
5 5
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100
INPUT DETAILS:
There are five landmarks.
Sample Output
90
OUTPUT DETAILS:
Bessie can get home by following trails 4, 3, 2, and 1.
这题各种单源最短路都能过
#include<cstdio>
#include<cstring>
int n,m,x,y,z,cnt,t,w=1;
int head[10001];
struct edge{
int to,next,v;
}e[50001];
int q[50001];
bool mark[50001];
int dist[50001];
inline void ins(int u,int v,int w)
{
e[++cnt].v=w;
e[cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
}
void insert(int u,int v,int w)
{
ins(u,v,w);
ins(v,u,w);
}
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void spfa()
{
q[1]=1;
mark[1]=1;
dist[1]=0;
while (t<w)
{
int now=q[++t];
for (int i=head[now];i;i=e[i].next)
if (dist[now]+e[i].v<dist[e[i].to])
{
dist[e[i].to]=dist[now]+e[i].v;
if (!mark[e[i].to])q[++w]=e[i].to;
}
mark[now]=0;
}
}
int main()
{
m=read();n=read();
memset(dist,127/3,sizeof(dist));
for(int i=1;i<=m;i++)
{
x=read();y=read();z=read();
insert(x,y,z);
}
spfa();
printf("%d",dist[n]);
}
bzoj1752 [Usaco2005 qua]Til the Cows Come Home的更多相关文章
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- 1753: [Usaco2005 qua]Who's in the Middle
1753: [Usaco2005 qua]Who's in the Middle Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 290 Solved: ...
- 1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 398 Solved: 242[Submit ...
- 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 ...
随机推荐
- SQL Server 通过一个表和另一个表联合 批量更新这个表的字段
UPDATE OutPzPersonSet SET cPerson = a.AAA --SELECT * FROM OutPzPersonSet d INNER JOIN AAAA a ON d.cz ...
- Python安装MySQLdb并连接MySQL数据库
当然了,前提是你已经安装了Python和MySQL.我的Python是2.6版本的. Python2.6的“Set”有点兼容性问题,自己照着改一下: http://sourceforge.net/fo ...
- Building bridges_hdu_4584(排序).java
Building bridges Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- HDU1285——确定比赛名次
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
- unity的坑
http://dearymz.blog.163.com/blog/static/20565742013341916919/ 编辑器: Hierarchy窗口中是场景中的Game Object列表 Pr ...
- [Redux] Passing the Store Down with <Provider> from React Redux
Previously, we wrote the Provider component by ourself: class Provider extends Component { getChildC ...
- 字符串匹配之horspool算法(简化的BM算法)
前面介绍在BF,KMP这些算法的时候老是提到BM这个东西,究竟这什么东西,有啥高深的,这些问题我们如今不去考虑.不知道,认真读前几篇文章的读者有没有发现前面的算法都是从模式串的前面開始匹配的,那我们就 ...
- C#扩展方法的理解
“扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型.” 这是msdn上说的,也就是你可以对String,Int,DataRow,DataTable等这些 ...
- WCF入门教程系列五
一.概述 WCF在通信过程中有三种模式:请求与答复.单向.双工通信.以下我们一一介绍. 二.请求与答复模式 描述: 客户端发送请求,然后一直等待服务端的响应(异步调用除外),期间处于假死状态,直到服务 ...
- unity——使用角色控制器组件+射线移动
首先要导入unity标准资源包Character Controllers 这个标准资源包,为了方便,还添加了两外一个资源包Scripts,后者包含了一些基本的脚本个摄像机脚本. 没错,这次我们要使用其 ...