题目链接:https://www.luogu.org/problemnew/show/P1339

解题思路:

一道简单的最短路水题,dijkstra解法模板思路:https://www.cnblogs.com/lipeiyi520/p/10340361.html

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int ff=0x3f3f3f;
int n,m,g[][],a,b,c;
bool vis[];
int dist[];
void dij(int s){
memset(vis,false,sizeof(vis));//初始时所有点都没有确定最短路
memset(dist,0x3f,sizeof(dist));//答案初始为无限大
dist[s]=;//原点最短路为0
for(int i=;i<n;i++){
int hh,mind=ff;
for(int j=;j<=n;++j){
if(!vis[j]&&dist[j]<mind){//找出于当前点相邻的距当前点最近的点
mind=dist[j];
hh=j;
}
}
vis[hh]=;
for(int j=;j<=n;++j){
dist[j]=min(dist[j],dist[hh]+g[hh][j]);//如果一个点a到原点距离加点a到当前点的距离小于当前点到原点距离,那么就更新
}
}
}
int main()
{
int ts,te;
memset(g,0x3f,sizeof(g)); //初始化图,是每个点到原点最短路都为无限大
cin>>n>>m>>te>>ts;
for(int i=;i<m;i++){//建图
cin>>a>>b>>c;
g[a][b]=c;
g[b][a]=c;
}
dij(ts);
cout<<dist[te];
return ;
}

洛谷 P1339 [USACO09OCT]热浪Heat Wave的更多相关文章

  1. 洛谷—— P1339 [USACO09OCT]热浪Heat Wave

    P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...

  2. 洛谷 P1339 [USACO09OCT]热浪Heat Wave (堆优化dijkstra)

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

  3. 洛谷P1339 [USACO09OCT]热浪Heat Wave(最短路)

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

  4. 洛谷 P1339 [USACO09OCT]热浪Heat Wave(dijkstra)

    题目链接 https://www.luogu.org/problemnew/show/P1339 最短路 解题思路 dijkstra直接过 注意: 双向边 memset ma数组要在读入之前 AC代码 ...

  5. 洛谷 P1339 [USACO09OCT]热浪Heat Wave(最短路)

    嗯... 题目链接:https://www.luogu.org/problem/P1339 这道题是水的不能在水的裸最短路问题...这里用的dijkstra 但是自己进了一个坑—— 因为有些城市之间可 ...

  6. 洛谷P1339 [USACO09OCT]热浪Heat Wave 题解

    题目传送门 这道题实际非常简单好奇是怎么变黄的... 其实也就是一个SPFA,本人非常懒,不想打邻接表,直接用矩阵就好啦... #include<bits/stdc++.h> using ...

  7. 洛谷P1339 [USACO09OCT]热浪Heat Wave

    思路:裸SPFA过一遍(建议使用邻接链表存储),无向图,无向图,无向图,重要的事情要说三遍!!!蜜汁RE是什么鬼????第九个点数组开到20K,第十个点数组开到30K才AC.或许我代码写的有bug?( ...

  8. 洛谷 1339 [USACO09OCT]热浪Heat Wave

    [题解] 最短路.那么直接写dijkstra就好了. #include<cstdio> #include<algorithm> #include<cstring> ...

  9. [最短路]P1339 [USACO09OCT]热浪Heat Wave

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

随机推荐

  1. Python常用的包

    Python常用的处理数据的包和它的Tutorial(点击每个包的名称): Numpy:提供对多维数组的支持,支持矢量运算,速度快 matplotlib.pyplot:图表的绘制 Pandas:基于 ...

  2. (转载)解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes

    今天想用用MySQL 数据库  谁知道老提示 1045 access denied for user 'root'@'localhost' using password yes 最后在csdn 上找到 ...

  3. eclipse无法启动问题记录

    几天没开eclipse,居然报错“can not unload……”,搜索答案发现没有准确的,遵从了一个多人顶赞的办法重下eclipse,把配置文件拷贝一份,结果悲剧了,虽然能够打开了,但我之前配置的 ...

  4. Design Pattern 设计模式1 - Strategy 1

    实现 : Defferent Heros attack Defferently. - 不同的英雄使用不用的招数 Strategy设计的思路: 基类A.更加小的基类B,新的继承类C: 1 从基类A中抽出 ...

  5. curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused

    今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...

  6. 关于npm的环境变量配置、prefix

    1.关于npm 的 prefix 在npm中安装全局文件时,npm会把他安装在npm里面配置的prefix路径下,查看prefix的方法是:npm config list/npm config ls/ ...

  7. QT实现FTP服务器(三)

    QFtpClient类的实现: #include "QFtpClient.h" #include <QDebug> #include <QThread> # ...

  8. sjtu oj 1201. SuperXOR

    Description Pangzi recently realized that bitwise XOR operation is just an addition without carries. ...

  9. Mac OS X 开发环境搭建之利用 Parallel Desktop 安装 CentOS 7 [转载]

    背景 在企业级软件系统中,数据库的地位是比较高的,而且一般都要求支持多种数据库,如 Oracle. DB2.MySQL 等,它们的最新版本大多都不再支持 Mac OS X 系统,所以装一个 Linux ...

  10. POJ1511 Invitation Cards —— 最短路spfa

    题目链接:http://poj.org/problem?id=1511 Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Tota ...