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 ...
随机推荐
- c语言通过时间种子产生随机数并选出最大值以及下标
1 #include <stdio.h> #include <stdlib.h> #include <time.h> //2016 10 10 void main( ...
- MySql按日期时间段进行统计(前一天、本周、某一天、某个时间段)
在mysql数据库中,常常会遇到统计当天的内容.例如,在user表中,日期字段为:log_time 统计当天 sql语句为: select * from user where date(log_tim ...
- loadrunner java 缺少必要的导入包报错
loadrunner 运行从eclipse中做好的脚本,ctrl + A 复制到loadrunner中来, 添加参数化的的语句:verifyCode = lr.eval_string (&quo ...
- tab切换jquery代码
http://immmmm.com/jquery-tab-switch-code-improved.html html <div id="sidebar-tab"> ...
- Android Fragment详解(三): 实现Fragment的界面
为fragment添加用户界面: Fragment一般作为activity的用户界面的一部分,把它自己的layout嵌入到activity的layout中. 一个 要为fragment提供layout ...
- Leetcode_num3_Same Tree
题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...
- oracle创建表空间-用户-角色-授权
1.创建数据表空间: SQL> create tablespace rusky_data datafile 'D:\rusky\rusky_data01,dbf' size 10M autoex ...
- CodeManage 源代码管理器v2.0发布
下载地址 欢迎大家提出宝贵的意见和bug
- C# XML,XmlDocument简单操作实例
private static string _Store = LocalPathHelper.CurrentSolutionPath + "/data/bookstore.xml" ...
- 利用java Base64 实现加密、解密
Base64加密解密 package com.stone.util; import java.io.UnsupportedEncodingException; import sun.misc.*; p ...