HDU 2544 最短路(最短路/spfa)
来源:互联网 发布:手机sql注入 编辑:程序博客网 时间:2024/05/22 07:50
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2544
代码:
#include <stdio.h>#include <queue>using namespace std;#define RANGE 101#define MAX 0x3f3f3f3fint cost[RANGE][RANGE];int d[RANGE];bool used[RANGE];int n,m;void spfa( int s ){ int i,now; // 初始化 for( i=1;i<=n;++i ) { d[i]=MAX; used[i]=false; } d[s]=0; queue <int> q; q.push(s); used[s] = true; while(!q.empty()) { now = q.front(); q.pop(); used[now] = false; for(i = 1; i <= n; i++) { if(d[i] > d[now] + cost[now][i]) { d[i] = d[now] + cost[now][i]; if(used[i] == 0) { q.push(i); used[i] = true; } } } }}int main(){ int i,j,A,B,C; while( scanf("%d%d",&n,&m) ) { if( !n && !m ) break; // 初始化 for( i=1;i<=n;++i ) for( j=1;j<=i;++j ) if( i==j ) cost[i][j]=0; elsecost[i][j]=cost[j][i]=MAX; for( i=0;i<m;++i ) { scanf("%d%d%d",&A,&B,&C); cost[A][B]=cost[B][A]=C; } spfa(1); printf("%d\n",d[n]); } return 0;}
0 0
- hdu 2544 最短路(最短路spfa)
- HDU 2544-最短路(最短路spfa)
- HDU 2544 最短路(最短路/spfa)
- hdu 2544 最短路(spfa)
- Spfa 最短路 HDU 2544
- hdu 2544 最短路-spfa
- hdu 2544 最短路 spfa
- HDU 2544 最短路 (SPFA)
- HDU 2544 最短路【SPFA】
- HDU 2544 最短路 SPFA
- HDU 2544 最短路 (Dijkstra || SPFA)
- hdu 2544 最短路(dijkstra||spfa)
- hdu-2544-最短路(SPFA)
- hdu 2544 最短路(SPFA算法)
- HDU 2544 最短路(Spfa)
- HDU 2544 最短路(spfa详解)
- 最短路(SPFA)
- 最短路 (Spfa)
- 剑指offer系列之17:二叉树的镜像
- 分治法求解最近点距
- 继承自定义类时,该类不能用@class导入
- 【追求进步】和为S的连续正数序列
- 重复利用的东西,记得最后清空
- HDU 2544 最短路(最短路/spfa)
- SDOI2016 Round1总结
- springMVC系列之(三) spring+springMVC集成(annotation方式)
- LeetCode 58. Length of Last Word
- Android平台中进程与线程的基本知识
- 重写系统左滑返回
- static的作用
- [ERP]IQC,IPQC,PQC,FQC,OQC是什么意思?是干什么的?
- 自定义copy