SPFA算法模板
来源:互联网 发布:代刷网 授权平台源码 编辑:程序博客网 时间:2024/06/05 10:35
#include<iostream>#include<cstdio>#include<queue>#include<cstring>using namespace std;const int size = 200010;int head[size],next[size],dist[size];struct dc{ int t,d;}l[size];bool use[size];int pri[size];int t,c,s,e;int tot = 1;void build(int f,int t,int d){ l[tot].d = d; l[tot].t = t; next[tot] = head[f]; head[f] = tot ++;}queue < int > q;void spfa(int s){ dist[s] = 0; use[s] = 1; q.push(s); while(!q.empty()) { int f = q.front(); q.pop(); use[f] = 0; for(int i = head[f] ; i ; i = next[i]) { int t = l[i].t; if(dist[t] > dist[f] + l[i].d) { dist[t] = dist[f] + l[i].d; pri[t] = f; if(!use[t]) { use[t] = 1; q.push(t); } } } }}int main(){ scanf("%d%d%d%d",&t,&c,&s,&e); for(int i = 1 ; i <= t ; i ++) dist[i] = 214748364; for(int i = 1 ; i <= c ; i ++) { int f,t,d; scanf("%d%d%d",&f,&t,&d); build(f,t,d); build(t,f,d); } spfa(s); printf("%d",dist[e]); return 0;}
例题codevs1557 , 两点间的最短路径
0 0
- 基础SPFA算法模板
- SPFA算法模板
- SPFA算法模板
- SPFA算法模板
- spfa 算法模板
- SPFA算法模板
- SPFA算法模板
- spfa算法模板
- Spfa算法模板
- hihocoder1093 SPFA算法模板
- SPFA算法模板
- SPFA算法模板
- Spfa算法 (模板源代码)
- Spfa算法 (模板源代码)
- hdu 2544 spfa算法模板
- 最短路【SPFA】算法模板
- 最短路SPFA算法模板
- 单源最短路 SPFA 算法模板
- 标点符号的英语名称
- C# 对象比较(值类型、引用类型)
- Fragment和Actiity的交互关系讲解(整理别人的)
- SLIC超像素生成算法
- IOS开发:动画1
- SPFA算法模板
- isfinite() isinf() isnan() isnormal()
- imalse:DDOS攻击仿真
- 代码整洁之道学习(一)
- textview的drawablle属性
- EditText中 InputType
- SSD算法 模板 匹配
- QT多线程中的互斥与同步
- 多表查询