#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 热浪【最短路】的更多相关文章

  1. 洛谷P1339 热浪

    P1339 热浪 529通过 1.3K提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 求助...为什么是未知错误… 求修正,貌似死循环 第 ...

  2. Luogu P1339 热浪Heat Wave

    Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...

  3. 洛谷P1339 热浪【最短路】

    题目:https://www.luogu.org/problemnew/show/P1339 题意:给定一张图,问起点到终点的最短路. 思路:dijkstra板子题. 很久没有写最短路了.总结一下di ...

  4. BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )

    普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ ...

  5. tyvj 1031 热浪 最短路

    热浪 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://tyvj.cn/p/1031 Description 德克萨斯纯朴的民眾们这个夏天正在遭受 ...

  6. P1339 热浪 最短路径模板题

    这么naive的题面一看就是最短路模板题~~~ ok.首先是floyd算法,tts,记得把k放在最外面就行了. #include <cstdio> #include <cstring ...

  7. P1339 热浪Heat Wave 洛谷

    https://www.luogu.org/problem/show?pid=1339 题目描述 The good folks in Texas are having a heatwave this ...

  8. bzoj 3408 热浪 最短路

    一道最短路的模板题,就当练习一下SPFA和dijkstra了 SPFA #include<bits/stdc++.h> using namespace std; struct edge{ ...

  9. noip2017考前整理(未完)

    快考试了,把我以前写过的题回顾一下.Noip2007 树网的核:floyd,推出性质,暴力.Noip2008 笨小猴:模拟Noip2008 火柴棒等式:枚举Noip2008 传纸条:棋盘dpNoip2 ...

随机推荐

  1. Java HashMap 四种遍历方式

    HashMap遍历方式包含以下4种: 1.遍历KeySet,再通过Key来getValue. 2.使用entrySet的迭代器. 3.foreach entrySet的方式. 3.foreache v ...

  2. apache 负载均衡

    此次使用mod_proxy的方式来实现的,因为在Apache2以上的版本中已经集成了,因此不需要再另行安装和配置了. 只需要把注释去掉即可,去掉以下模块的注释: LoadModule proxy_mo ...

  3. 解决mysql登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)问题

    问题描述: 在ubuntu14.04上安装完MYSQL后,MYSQL默认给分配了一个默认密码,但当自己在终端上使用默认密码登录的时候,总会提示一个授权失败的错误. 报错信息:Access denied ...

  4. cornerstone使用beyond compare比较工具

    prefrences->general->external compare tool->open script foder 新建一个bc.sh文件(名字可以任意,sh后缀即可)保存到 ...

  5. 在Django中连接MySQL数据库(Python3)

    我的环境:      python3.6,      Django2.1.5,      MySQL8.0.15,      win10,      PyCharm, 要求:已经安装了MySQL数据库 ...

  6. C#中实现文件拖放打开的方法

    C#中实现文件拖放打开的方法 设置Form属性 AllowDrop = True; 在Form事件中 private void Form1_DragDrop(object sender, DragEv ...

  7. tomcat下载页面多个版本区别

  8. scanf 与fgets

    scanf: 1.以输入字符串也可以输入数字 . 2.遇到空格就停止.3.会有segmentation fault. fgets: 1.只能输入字符串.2.回车才会停止.3.不会有segmenntat ...

  9. 关键字Lock的简单小例子

    一.什么是Lock? Lock——字面上理解就是锁上:锁住:把……锁起来的意思: 为什么要锁?要锁干什么?——回到现实中可想象到,这个卫生间我要上,其他人不要进来!(所以我要锁住门):又或者土味情话所 ...

  10. cf1067b

    题意简述:判断所给图是不是一个k递归图 这是一个2递归图 题解:仔细观察发现中心点一定是直径的中点,因此找到直径中点之后进行bfs判断即可,这里注意判断递归层次太大也不符合 const int max ...