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

CODE:

 #include<iostream>
#include<queue>
using namespace std;
queue<int>q;
struct Edge{
int pre,to,w;
}edge[];
int head[];
bool if_q[];
int dis[];
int T, C, Ts, Te,Rs, Re,Ci;
int num_edge;
inline void add_edge(int from,int to,int w)
{
edge[++num_edge].pre=head[from];
edge[num_edge].to=to;
edge[num_edge].w=w;
head[from]=num_edge;
}
inline void spfa(int u)
{
q.push(u);
if_q[u]=true;
while(!q.empty())
{
u=q.front();
for(int i=head[u]; i!=; i=edge[i].pre)
{
int v=edge[i].to;
if(dis[u]+edge[i].w<dis[v])
{
dis[v]=dis[u]+edge[i].w;
if_q[v]=true;
q.push(v);
}
}
if_q[u]=false;
q.pop();
}
}
int main()
{
for(int i=;i<;i++)
dis[i]=0x7fffffff;
cin>>T>>C>>Ts>>Te;
for(int i=;i<C;i++)
{
cin>>Rs>>Re>>Ci;
add_edge(Rs,Re,Ci);
add_edge(Re,Rs,Ci);
}
dis[Ts]=;
spfa(Ts);
cout<<dis[Te];
return ;
}

注:就是模板题,STL大法好,哈哈哈。

洛谷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

    题目链接: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(最短路)

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

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

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

  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写代码,有一些不习惯,比如if.else.for.def后要加:.假设换一个编译工具可能会好点,否则仅仅能每次执行的时候查看错误信息.它的优点也正是这里不须要每条语句输入;.不须要 ...

  2. lsyncd + rsync 实时同步搭建

    一.inotify和lsync inotify和lsyncd对比一下,发现虽然lsyncd没有inotify那么真正的实时同步,但是lsyncd的同步基本上可以满足基本实时同步的要求,而且lsyncd ...

  3. [Node.js] Setup Local Configuration with Node.js Applications

    Github To stop having to change configuration settings in production code and to stop secure informa ...

  4. Spring 新手教程(三) 注入和自己主动装配

         Spring注入是指在启动Spring容器载入bean配置的时候.对类变量的赋值. 两种经常使用注入方式:设值注入和构造注入 以下就这部分知识看代码以及代码中的注解: 1.首先看Spring ...

  5. Windowns 无法启动 Office Software Protection Platform 服务,系统找不到指定的文件

    导致该服务无法启动的原因是,用kms8激活了win7后又用oem8激活试了下,结果就这样,然后就无法激活了,状态ID都不可用.试过禁用计划任务项目,重建MBR,重建PBR,都无效果.最后在这里找到了解 ...

  6. DirectFB学习之移植到nuc972平台 标签: DirectFBlinux图形加速驱动【转】

    本文转载自:http://blog.csdn.net/jxgz_leo/article/details/70137304 [nuc972开发板购买地址,感谢支持](https://shop102749 ...

  7. 电脑升级win10后visio的问题

    上周由于电脑意外蓝屏,系统从win7升级到了win10,昨天工作写文档时才发现缺少画图的工具,于是按照了visio2013,在编辑设计图时发现,一旦用visio打开或编辑图后再到word里设计图的内容 ...

  8. Intervals(差分约束系统)

    http://poj.org/problem?id=1201 题意:给定n个整数闭区间[a,b]和n个整数c,求一个最小的整数集合Z,满足Z里边的数中范围在闭区间[a,b]的个数不小于c个. 思路:根 ...

  9. Power Network(最大流(EK算法))

    http://poj.org/problem?id=1459 题意:有一个电路网络,每个节点可以产生.传递.消耗若干电量,有点线连接结点,每个电线有最大传输量,求这个网络的最大消费量. 思路:从源点到 ...

  10. prim解决最小生成树问题

    #include <iostream> #include <algorithm> #include <stdio.h> #include <math.h> ...