P1339 热浪【最短路】
#include <bits/stdc++.h>
#define dbg(x) cout << #x << "=" << x << endl
#define eps 1e-8
#define pi acos(-1.0) using namespace std;
typedef long long LL; template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} namespace _buff {
const size_t BUFF = << ;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, , BUFF, stdin);
}
return ib == ie ? - : *ib++;
}
} int qread() {
using namespace _buff;
int ret = ;
bool pos = true;
char c = getc();
for (; (c < '' || c > '') && c != '-'; c = getc()) {
assert(~c);
}
if (c == '-') {
pos = false;
c = getc();
}
for (; c >= '' && c <= ''; c = getc()) {
ret = (ret << ) + (ret << ) + (c ^ );
}
return pos ? ret : -ret;
} const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f; int head[maxn << ], edge[maxn << ], w[maxn << ], nxt[maxn << ];
int cnt; inline void BuildGraph (int u, int v, int c) {
cnt++;
edge[cnt] = v;
nxt[cnt] = head[u];
w[cnt] = c;
head[u] = cnt;
} struct node {
int u,v;
bool operator <(const node &t) const {
return u > t.u;
}
}; int n,m,s,t;
int dis[maxn]; priority_queue < node > q; void dijkstra(int s) {
for (int i = ; i <= n; ++i) {
dis[i] = inf;
}
dis[s] = ;
node temp;
temp.u = ;
temp.v = s;
q.push(temp);
while(!q.empty()) {
int u = q.top().v;
int d = q.top().u;
q.pop();
if(d != dis[u]) continue;
for (int i = head[u]; i; i = nxt[i]) {
int v = edge[i];
int c = w[i];
if(dis[v] > dis[u] + c) {
dis[v] = dis[u] + c;
node p;
p.u = dis[v], p.v = v;
q.push(p);
}
}
}
} int main()
{
scanf("%d %d %d %d",&n, &m, &s, &t);
int a, b, c;
for (int i = ; i <= m; ++i) {
scanf("%d %d %d",&a, &b, &c);
BuildGraph(a, b, c);
BuildGraph(b, a, c);
}
dijkstra(s);
printf("%d\n",dis[t]);
return ;
}
P1339 热浪【最短路】的更多相关文章
- 洛谷P1339 热浪
P1339 热浪 529通过 1.3K提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 求助...为什么是未知错误… 求修正,貌似死循环 第 ...
- Luogu P1339 热浪Heat Wave
Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...
- 洛谷P1339 热浪【最短路】
题目:https://www.luogu.org/problemnew/show/P1339 题意:给定一张图,问起点到终点的最短路. 思路:dijkstra板子题. 很久没有写最短路了.总结一下di ...
- BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )
普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ ...
- tyvj 1031 热浪 最短路
热浪 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://tyvj.cn/p/1031 Description 德克萨斯纯朴的民眾们这个夏天正在遭受 ...
- P1339 热浪 最短路径模板题
这么naive的题面一看就是最短路模板题~~~ ok.首先是floyd算法,tts,记得把k放在最外面就行了. #include <cstdio> #include <cstring ...
- P1339 热浪Heat Wave 洛谷
https://www.luogu.org/problem/show?pid=1339 题目描述 The good folks in Texas are having a heatwave this ...
- bzoj 3408 热浪 最短路
一道最短路的模板题,就当练习一下SPFA和dijkstra了 SPFA #include<bits/stdc++.h> using namespace std; struct edge{ ...
- noip2017考前整理(未完)
快考试了,把我以前写过的题回顾一下.Noip2007 树网的核:floyd,推出性质,暴力.Noip2008 笨小猴:模拟Noip2008 火柴棒等式:枚举Noip2008 传纸条:棋盘dpNoip2 ...
随机推荐
- Vue生命周期和钩子函数及使用keeplive缓存页面不重新加载
Vue生命周期 每个Vue实例在被创建之前都要经过一系列的初始化过程,这个过程就是vue的生命周期,在这个过程中会有一些钩子函数会得到回调 Vue中能够被网页直接使用的最小单位就是组件,我们经常写的: ...
- Gridview的stretchMode等属性详解
<GridView android:id="@+id/grid"android:layout_width="fill_parent"android:lay ...
- linux--解决celery消息中间件带来的一系列问题
启动celery定时任务 1.celery -A OpsManage beat -l info -S django 2.celery -A OpsManage worker -l info 此时消息中 ...
- java开发学生信息管理系统 源码
开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MYSQL数据库 运行效果图 源码及原文链接:https://javadao.xyz/forum.php?mo ...
- XPath简介、功能及使用方法
html = '''<html><head><title>The Dormouse's story</title></head><bo ...
- 常见CSS3选择器和文本字体样式汇总
常见的CSS3选择器包含:常用基本.属性.伪类.层级(组合)选择器,具体使用情况建议先阅读css选择器四大类:基本.组合.属性.伪类对于选择器的使用有一个基本了解,选择器的作用在于通过它找到元素,并且 ...
- 1.4掌握日志工具的使用——Android第一行代码(第二版)笔记
Android中的日志工具类是Log(android.util.Log),这个类中提供了如下5个方法来供我们打印日志. Log.v():用于打印那些最为琐碎的.意义最小的日志信息.对应级别verbos ...
- Android9.0 Settings 修改踩坑记录
问题现象 上图展示的很清楚,当系统语言为中文时,PreferenceScreen 中的折叠项 summary 描述重复显示的 bug,系统语言为英文时正常. 修改历程 先搜索 当前显示了 字符串,还真 ...
- java自学:从零基础到入门系列--java环境变量的配置JDK的下载安装图解
一.首先去官网下载 Java 语言的软件开发工具包–JDK,下载JDK8即可,下载地址为:https://www.oracle.com/technetwork/java/javase/download ...
- 7.python虚拟环境详解
1.为什么创建虚拟环境? 和其他大多数现代编程语言一样,Python对包和模块的下载.存储以及管理有其自己的一套方法,Python的包一般都存在几个特定的地方,大部分系统包会存在sys.prefix指 ...