题目链接: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. 【万里征程——Windows App开发】控件大集合1

    加入控件的方式有多种.大家更喜欢哪一种呢? 1)使用诸如 Blend for Visual Studio 或 Microsoft Visual Studio XAML 设计器的设计工具. 2)在 Vi ...

  2. notepad++的f90配置文件

    notepad++仅支持f77格式的,所以f90格式需要重新定义配置文件 传送门: http://ehc.ac/p/notepad-plus/discussion/331753/thread/8f72 ...

  3. F08标准中Open命令的newunit选项

    从gfortran 4.5开始Open命令开始支持newunit选项,示例如下: integer :: u open(newunit=u, file="log.txt", posi ...

  4. 使用Javamelody验证struts-spring框架与springMVC框架下action的訪问效率

    在前文中我提到了关于为何要使用springMVC的问题,当中一点是使用springMVC比起原先的struts+spring框架在效率上是有优势的.为了验证这个问题,我做了两个Demo来验证究竟是不是 ...

  5. Delphi和C++的语法区别 (关于构造和析构)

    目录 Delphi永远没办法在栈上创建一个对象 Delphi的构造函数更象是个类方法(静态成员函数) Delphi的析构函数中可以调用纯虚方法 Delphi在构造对象时自动将成员变量清零 Delphi ...

  6. 2016/05/25 PHP mysql_insert_id() 函数 返回上一步 INSERT 操作产生的 ID

    定义和用法 mysql_insert_id() 函数返回上一步 INSERT 操作产生的 ID. 如果上一查询没有产生 AUTO_INCREMENT 的 ID,则 mysql_insert_id() ...

  7. MapReduce算法形式四:mapjoin

    案例四:mapjoin(对个map共同输入,一个reduce) 这个方法主要解决的是,几个表之间的比较,类似于数据库的内外连接,还有一些左右连接之类的,简而言之就是,A表没有的B表有,B表有的A没有或 ...

  8. 今日头条上看到的js面试题和答案

    用js判断字符中每个字符出现的次数, 答案是var info = arr.split('').reduce((a,b)=>(console.log(a,b),a[b]++ || (a[b]=1) ...

  9. SWT.Shell

    import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class SWT_Shell ...

  10. (C)理解#define write(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b))

      理解 #define write(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b)) 嵌入式系统编程,要求程序员能够利用C语言访问固 ...