题目描述
The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for good eating but are not so adept at creating creamy delicious dairy products. Farmer John is leading the charge to deliver plenty of ice cold nutritious milk to Texas so the Texans will not suffer the heat too much.

FJ has studied the routes that can be used to move milk from Wisconsin to Texas. These routes have a total of T (1 <= T <= 2,500) towns conveniently numbered 1…T along the way (including the starting and ending towns). Each town (except the source and destination towns) is connected to at least two other towns by bidirectional roads that have some cost of traversal (owing to gasoline consumption, tolls, etc.). Consider this map of seven towns; town 5 is the

source of the milk and town 4 is its destination (bracketed integers represent costs to traverse the route):

                          [1]----1---[3]-/               \[3]---6---[4]---3--[3]--4/               /       /|5         --[3]--  --[2]- |\       /        /       |[5]---7---[2]--2---[3]---|       /[1]------

Traversing 5-6-3-4 requires spending 3 (5->6) + 4 (6->3) + 3 (3->4) = 10 total expenses.

Given a map of all the C (1 <= C <= 6,200) connections (described as two endpoints R1i and R2i (1 <= R1i <= T; 1 <= R2i <= T) and costs (1 <= Ci <= 1,000), find the smallest total expense to traverse from the starting town Ts (1 <= Ts <= T) to the destination town Te (1 <= Te <= T).

德克萨斯纯朴的民眾们这个夏天正在遭受巨大的热浪!!!他们的德克萨斯长角牛吃起来不错,可是他们并不是很擅长生產富含奶油的乳製品。Farmer John此时以先天下之忧而忧,后天下之乐而乐的精神,身先士卒地承担起向德克萨斯运送大量的营养冰凉的牛奶的重任,以减轻德克萨斯人忍受酷暑的痛苦。

FJ已经研究过可以把牛奶从威斯康星运送到德克萨斯州的路线。这些路线包括起始点和终点先一共经过T (1 <= T <= 2,500)个城镇,方便地标号為1到T。除了起点和终点外地每个城镇由两条双向道路连向至少两个其它地城镇。每条道路有一个通过费用(包括油费,过路费等等)。

给定一个地图,包含C (1 <= C <= 6,200)条直接连接2个城镇的道路。每条道路由道路的起点Rs,终点Re (1 <= Rs <= T; 1 <= Re <= T),和花费(1 <= Ci <= 1,000)组成。求从起始的城镇Ts (1 <= Ts <= T)到终点的城镇Te(1 <= Te <= T)最小的总费用。

输入格式
第一行: 4个由空格隔开的整数: T, C, Ts, Te

第2到第C+1行: 第i+1行描述第i条道路。有3个由空格隔开的整数: Rs, Re和Ci

输出格式
一个单独的整数表示从Ts到Te的最小总费用。数据保证至少存在一条道路。

输入输出样例
输入 #1复制
7 11 5 4
2 4 2
1 4 3
7 2 2
3 4 3
5 7 5
7 3 3
6 1 1
6 3 4
2 4 3
5 6 3
7 2 1
输出 #1复制
7
说明/提示
【样例说明】

5->6->1->4 (3 + 1 + 3)

水题

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>using namespace std;const int maxn = 20005;
int head[maxn],nex[maxn],to[maxn],val[maxn],tot;
int d[maxn],vis[maxn];void add(int x,int y,int z)
{to[++tot] = y;nex[tot] = head[x];val[tot] = z;head[x] = tot;
}void spfa(int sta)
{queue<int>q;memset(d,0x3f,sizeof(d));d[sta] = 0;q.push(sta);vis[sta] = 1;while(!q.empty()){int now = q.front();q.pop();vis[now] = 0;for(int i = head[now];i;i = nex[i]){int v = to[i],w = val[i];if(d[v] > d[now] + w){d[v] = d[now] + w;if(!vis[v]){q.push(v);vis[v] = 1;}}}}
}int main()
{int t,c,ts,te;scanf("%d%d%d%d",&t,&c,&ts,&te);for(int i = 1;i <= c;i++){int x,y,z;scanf("%d%d%d",&x,&y,&z);add(x,y,z);add(y,x,z);}spfa(ts);printf("%d\n",d[te]);return 0;
}

P1339 [USACO09OCT]热浪Heat Wave(最短路水题)相关推荐

  1. P1339 [USACO09OCT]热浪Heat Wave(SPFA)

    -------------------------------------- 农夫约翰再显神威,双向热浪,双倍数组 (双倍大小,否则RE) ------------------------------ ...

  2. [USACO09OCT]热浪Heat Wave

    未经同意,不得转载. The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make ...

  3. 题解- [USACO09OCT]热浪Heat Wave

    题目描述 The good folks in Texas are having a heatwave this summer. Their Texas Longhorn cows make for g ...

  4. 【洛谷1339 [USACO09OCT]】热浪Heat Wave 图论+最短路

    AC代码 #include<bits/stdc++.h> using namespace std; const int MAXN=62000+10,INF=999999; struct E ...

  5. 信息学奥赛一本通 1379:热浪(heatwv) | 洛谷 P1339 [USACO09OCT]Heat Wave G

    [题目链接] ybt 1379:热浪(heatwv) 洛谷 P1339 [USACO09OCT]Heat Wave G [题目考点] 1. 图论:最短路径 [解题思路] 首先抽象建模.城镇为顶点,道路 ...

  6. bzoj 3386 bzoj 3408: [Usaco2009 Oct]Heat Wave 热浪(最短路)

    3408: [Usaco2009 Oct]Heat Wave 热浪 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 301  Solved: 223 [ ...

  7. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  8. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  9. 2014ACM/ICPC亚洲区广州站- HDU-5127~5137,B(暴力+几何)E(签到水题)K(Dijkstra板子)

    已经开始挖区域赛的坑了,CF已经不够打了,其实CF打不动了. 一点一点写吧,看看最后能写多少. B-The E-pang Palace(暴力+几何) 题目链接:http://acm.hdu.edu.c ...

最新文章

  1. python输入多个数字后续操作_有效地确定后续数字范围中的数字是否在有序列表中. (在Python中)...
  2. KG-知识图谱入门-王昊奋课程详细笔记(附课件、课程链接与详细笔记) 内有资源
  3. 明星居然来我们宜昌保利时代拍戏——电影《被光抓走的人》
  4. java B2B2C 仿淘宝电子商城系统-Spring Cloud Eureka参数配置项详解
  5. ibatis mysql sqlmapconfig_iBATIS sqlMapConfig配置详解
  6. Lync Server 2013企业版部署系列之四:SQL准备
  7. 智能设备逆向工程之外部Flash读取与分析篇
  8. java后端参数默认值添加枚举_利用自定义Validator和枚举类来限定接口的入参
  9. 昇腾 AI 成就了一群玩船模的大学生——创新,有“模”有 Young
  10. 教你学习CI框架codelgniter——CI框架基本配置
  11. python在预算执行审计中的应用_重庆万州:运用“大数据+” 预算执行审计取得成效...
  12. 集线器、交换机、网桥区别
  13. 【联盛德W806上手笔记】四、PWM模块
  14. 腾讯视频 Node.js 服务是如何支撑国庆阅兵直播高并发的?
  15. Camera2 打开相机预览界面
  16. jqGrid 学习笔记整理——基础篇
  17. 机器学习模型 知乎_深度剖析知乎目前的内容架构模型
  18. 百度地图绘制行驶轨迹、折线上添加箭头、修改地图底色
  19. 系统间数据交换的5种方式
  20. 描述相机内部参数以及外部参数

热门文章

  1. Kubernetes系列教程(二)---集群网络之Flannel核心原理
  2. 猪八戒是个好员工——张教授
  3. 用固态U盘让你的办公环境随身移动
  4. CubeMx笔记 -- IIC(位带操作实现)+ IO拓展
  5. appium java 虫师_如何在Appium中使用AI定位
  6. 进销存免费管理软件 进销存免费软件推荐 免费进销存
  7. 不要仅为85%的用户设计:关注无障碍设计
  8. android 微信引导界面,昨天下午,微信启动页面图换了,但却害苦了安卓手机用户!...
  9. 阿里巴巴 DevOps 转型后的运维平台建设
  10. 分期的秘密:名义利率和实际利率