嗯...

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

这道题是水的不能在水的裸最短路问题...这里用的dijkstra

但是自己进了一个坑——

  因为有些城市之间可能还没有道路,自己只是将其初始化为0,而应该初始化为0x3f3f,从而表示两个城市之间没有道路...

AC代码:

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std;
const int inf = 0x3f3f;
int n, c, ts, te, dis[], vis[], g[][]; inline void dijkstra(int x){
for(int i = ; i <= n; i++) dis[i] = (i == x ? : inf);
for(int i = ; i <= n; i++){
int t = , y = inf;
for(int j = ; j <= n; j++) if(!vis[j] && dis[j] <= y) y = dis[t = j];
vis[t] = ;
for(int j = ; j <= n; j++) dis[j] = min(dis[j], dis[t] + g[t][j]);
}
} int main(){
memset(g, 0x3f3f, sizeof(g));//初始化!!
scanf("%d%d%d%d", &n, &c, &ts, &te);
for(int i = ; i <= c; i++){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u][v] = g[v][u] = w;
}
dijkstra(ts);
printf("%d", dis[te]);
return ;
}

AC代码

洛谷 P1339 [USACO09OCT]热浪Heat Wave(最短路)的更多相关文章

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

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

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

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

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

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

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

    题目链接:https://www.luogu.org/problemnew/show/P1339 解题思路: 一道简单的最短路水题,dijkstra解法模板思路:https://www.cnblogs ...

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

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

  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. 出现 HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 异常

    出现这种异常在网上搜了搜 ,大多数都是说jdk和tomcat版本的问题:而我前几天都是运行得好好的,今天就编写了代码一运行项目发现报了这个错误.后台仔细看了看错误信息.结果是在你的项目中有相同的req ...

  2. c#逐行读取文件到数组

    /// <summary> /// 逐行读取文件到泛型数组 /// </summary> /// <param name="FilePath"> ...

  3. jquery获取ul下的所有li个数

    通过jquery获取ul下所有li的个数(eg) $("ul li").length 通过jquery设置标签css的样式(eg)$("#div").css({ ...

  4. 能使Oracle索引失效的七大限制条件

    Oracle 索引的目标是避免全表扫描,提高查询效率,但有些时候却适得其反. 例如一张表中有上百万条数据,对某个字段加了索引,但是查询时性能并没有什么提高,这可能是 oracle 索引失效造成的.or ...

  5. DFC-3C和DFC-3B的区别和注意事项

    1.Product numbers:WS-F6K-DFC(=)WS-F6K-DFC3A(=)WS-F6K-DFC3B(=)WS-F6K-DFC3BXL(=)WS-F6K-DFC3C(=)WS-F6K- ...

  6. PHP array_chunk() 妙用

    定义和用法 array_chunk()函数把一个数组分割为新的数组块. array_chunk(array,size,preserve_keys); 参数 描述 array 必需.规定要使用的数组. ...

  7. NMAP输出结果中CPE的含义【转】

    CPE全称是Common Platform Enumeration,意思是通用平台枚举项:它是NMAP对识别出来的软件.操作系统和硬件的一种命名方式:格式如下: cpe:/<part>:& ...

  8. web应用程序上传文件 超过了最大请求长度

    具体问题如下图 具体问题描述:在web应用程序中,上传了200M的文件,出现了如上图的问题,上传较小文件的时候,没有任何的问题.但是,测试的能力,不容小觑,真真的会测试的很全面.测试到了这个问题,好吧 ...

  9. SpringBoot启动后自动打开浏览器访问项目

    之前我们用SSM或者SSH进行JAVA WEB开发的时候,IDEA 需要配置Tomcat然后把项目放到tomcat运行,tomcat启动的时候会自动打开浏览器去访问项目,但是SpringBoot是内嵌 ...

  10. 6_8 树(UVa548)<从中序和后序恢复二叉树>

    你的任务是找出一棵二叉树中最小路径上终端节点(树叶,leaf node)的值.所谓路径乃指从根节点(root)旅行到任一终端节点.路径的值为所经过的节点的值的和(包含根节点及终端节点).而最小路径就是 ...