#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. 【Bullet引擎】刚体类 —— btRigidBody

    btRigidBody类主要用于刚体数据的计算. 在模拟刚体动画过程中,可以使用btRigidBody类获取所保存的刚体对象,进而控制刚体对象的旋转和位移.进行刚体模拟计算需要经常用到此类. API: ...

  2. mapreduce清洗数据

    继上篇 MapReduce清洗数据 package mapreduce; import java.io.IOException; import org.apache.hadoop.conf.Confi ...

  3. gcc和g++的区别:安装、版本、编译(转)

    用以下命令: yum install gcc 安装的只有gcc,而不会安装g++.gcc是编译器合集,而gcc-g++或简称g++则是C++编译器.gcc成为了编译器的选择器.gcc通过识别被编译的源 ...

  4. File、FileStream、StreamWriter、StringWriter文件使用总结

    一.File 1.File为静态类 File类,是一个静态类,支持对文件的基本操作,包括创建,拷贝,移动,删除和打开一个文件.File类方法的参量很多时候都是路径path.主要提供有关文件的各种操作, ...

  5. 使用A线程打印1-52,B线程打印A-Z,要求按照12A34B56C....5152Z的顺序进行交替打印

    多线程同步问题,都需要用到监视器,用来监视资源是否可用.C++中使用condition_variable,Java中使用Condition来实现同步. 1. 实现思路 需要有一个全局变量控制当前该哪个 ...

  6. 【转载】signal(SIGCHLD, SIG_IGN)和signal(SIGPIPE, SIG_IGN)

    来源:https://blog.csdn.net/guotao1983/article/details/82118218 signal(SIGCHLD, SIG_IGN) 因为并发服务器常常fork很 ...

  7. IO包中的RandomAccessFile类

    RandomAccessFile RandomAccessFile 是随机访问文件的类.它支持对文件随机访问的读取和写入,即我们也可以从指定的位置读取/写入文件数据,因为该类在其内部封装了一个数组和指 ...

  8. Django 博客单元测试:测试评论应用

    作者:HelloGitHub-追梦人物 文中所涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 评论应用的测试和博客应用测试的套路是一样的. 先来建立测试文件的目录结构.首先在 c ...

  9. npm安装Vue.js

    我之前是有安装过npm的 使用淘宝 NPM 镜像 $ npm install -g cnpm --registry=https://registry.npm.taobao.org 查看nmp版本 $ ...

  10. RadioButton改写的开关按钮

    先上效果图: 这个控件其实是俩个RadioButton,通过样式就可以实现. 样式资源: <Style x:Key="Tong_Yong_RadioButtonStyle" ...