#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 40 struct Edge
{
int e, w;
Edge(int e=,int w=) : e(e), w(w) {}
};
int Path[maxn], n, dist[maxn];
bool vis[maxn];
vector<Edge> G[maxn]; void Spfa(int Star,int End)
{
Edge P, Pn;
dist[Star] = ;
queue<Edge> Q;
Q.push(Edge(Star,)); while( !Q.empty() )
{
P = Q.front();
Q.pop();
vis[P.e] = true; int len = G[P.e].size(); for(int i=; i<len; i++)
{
Pn = G[P.e][i]; if(dist[Pn.e] > dist[P.e] + Pn.w)
{
dist[Pn.e] = dist[P.e] + Pn.w;
Path[Pn.e] = P.e;
if( !vis[Pn.e] )
{
Q.push(Pn);
vis[Pn.e] = true;
}
}
}
}
} void PutPath(int Star,int End)
{
if(Star == End)
{
printf("%d", Star);
return ;
} PutPath(Star, Path[End]); printf("---->%d", End);
}
void Init()
{
for(int i=; i<=n; i++)
{
G[i].clear();
dist[i] = INF;
vis[i] = false;
Path[i] = i;
}
} int main()
{
int m;
cin >> n >> m; Init(); for(int i=; i<=m; i++)
{
int a, b, c;
cin >> a >> b >> c;
G[a].push_back(Edge(b,c));
} Spfa(, n); printf("%d\n", dist[n]); PutPath(,n); return ;
}
/*
4 3
1 2 1
2 3 1
3 4 1
*/

SPFA 最短路径打印方法的更多相关文章

  1. DebugLog 打印方法执行时间

    DebugLog 打印方法执行时间 用于方便调试性能问题的打印插件.给访法加上@DebugLog,就能输出该方法的调用参数,以及执行时间. Project gradle配置 // Top-level ...

  2. 转网页WB.ExecWB控件打印方法

    网页WB.ExecWB控件打印方法 2010-02-01 12:48 代码: <table width="100%" cellpadding="1" on ...

  3. js打印方法总结

    前段时间做web项目用到了页面打印,在网上找了些资料,自己也试了很多方法,将这些方案列出下: 1.window.print()方法打印,所有主要浏览器都支持 print() 方法 这个方法很实用,只需 ...

  4. 实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法

    实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法 #import <Found ...

  5. Swift中自定义Log打印方法

    系统如何调用super方法 系统默认只会在构造函数中,自动调用super.init()方法,而且是在所写方法的尾部进行调用. 在其他函数中,如何需要调用父类的默认实现,都需要手动去实现. 如果在构造函 ...

  6. Swift中自定义打印方法

    // 1.获取打印所在的文件 let file = ( #file as NSString).lastPathComponent // 2.获取打印所在的方法 let funcName = #func ...

  7. C/S模式下的打印方法

     C/S模式使用润乾报表时有两种打印方法(都使用设计器授权) 1.         使用加密狗打印 这种方式需要使用加密狗,适用于客户端较少时 2.         使用api调用打印方法实现打印 ...

  8. 使用打印方法时,要先引用命名空间: Using System.Drawing.Pringing

    使用打印方法时,要先引用命名空间: Using System.Drawing.Pringing PrintDocument类的重要属性和方法:属性:DocumentName  设置打印文档时要显示的文 ...

  9. Swift 自定义打印方法

    Swift 自定义打印方法 代码如下 // MARK:- 自定义打印方法 func MLLog<T>(_ message : T, file : String = #file, funcN ...

随机推荐

  1. dede 留言簿 多个

    使用后台的[模块]-[模块生成向导],然后填写一下资料 PS:complaints 是之前做的一个"举报投诉"的留言簿意思,这里用作非常多文件名称和新建数据表的名字,所以替换就可以 ...

  2. Spring4.0支持Groovy配置

    介绍 前一段时间观注了一下Spring4.0的一些特性,当中就有对Groovy配置的支持.因为临时还没有很深入的研究.所以举个小样例来说明一下怎样支持Groovy配置. package shuai.s ...

  3. php 自定义求数组差集,效率比自带的array_diff函数还要快(转)

    <?phpfunction array_different($array_1, $array_2) { $array_2 = array_flip($array_2); //将数组键值调换 fo ...

  4. Qt 属性

      Qt提供了一套和一些编译器提供商也提供的属性系统类似的完善的属性系统.然而,作为一个不依赖编译器和平台的库,Qt不能依赖像__property或者[property]那样的非标准编译器特征.我们的 ...

  5. 怎样找Android里自带的数据库?

    首先先让它显示出来. 窗口window下的Show View 下的File Explorer(other里), 这时File Explorer窗口 就会显示出来,下一步我们找到data下的data,然 ...

  6. JPA事务回滚配置

    <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.or ...

  7. sql - sum() 和 count() 函数的区别

    对sql一直都是蜻蜓点水,突然也觉得对这两个函数的区别有点朦胧,查了一下,在这里说一下: sum():主要用于累加求和. count():主要用于行(记录)的统计.

  8. JAVA-4-斐波列

    public class Ch049 { public static void main(String[] args) { // TODO 自动生成的方法存根 int a = 1, b = 1; fo ...

  9. 【USACO 2.3.2】奶牛家谱

    [题目描述] 农民约翰准备购买一群新奶牛.在这个新的奶牛群中,每一个母亲奶牛都生两小奶牛.这些奶牛间的关系可以用二叉树来表示.这些二叉树总共有N个节点(3 <= N < 200).这些二叉 ...

  10. MyBatis学习笔记(2)——缓存

    一级缓存:基于PerpetualCache的HashMap本地缓存,其存储作用域为Session,当Session flush或 close之后,该Session 中的所有Cache将被清空 二级缓存 ...