#include <iostream>

using namespace std;

int m, n, u[100010], v[100010], w[100010];
int check;
int dis[100010];

int main(){
cin >> n >> m;
for(int i = 1; i <= m; i ++) cin >> u[i] >> v[i] >> w[i];
for(int i = 1; i <= n; i ++) dis[i] = 999999999;
dis[1] = 0;
for(int i = 1; i <= n - 1; i ++){
check = 0;
for(int j = 1; j <= m; j ++){
if(dis[v[j]] > dis[u[j]] + w[j]){
dis[v[j]] = dis[u[j]] + w[j];
check = 1;
}
}
if(check == 0) break;
}
for(int i = 1; i <= n; i ++) cout << dis[i] << " " ;
return 0;
}

BELLMEN-FORD普通的更多相关文章

  1. ACM/ICPC 之 网络流入门-Ford Fulkerson与SAP算法(POJ1149-POJ1273)

    第一题:按顾客访问猪圈的顺序依次构图(顾客为结点),汇点->第一个顾客->第二个顾客->...->汇点 //第一道网络流 //Ford-Fulkerson //Time:47M ...

  2. ACM/ICPC 之 最短路径-Bellman Ford范例(POJ1556-POJ2240)

    两道Bellman Ford解最短路的范例,Bellman Ford只是一种最短路的方法,两道都可以用dijkstra, SPFA做. Bellman Ford解法是将每条边遍历一次,遍历一次所有边可 ...

  3. poj1860 bellman—ford队列优化 Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22123   Accepted: 799 ...

  4. uva 558 - Wormholes(Bellman Ford判断负环)

    题目链接:558 - Wormholes 题目大意:给出n和m,表示有n个点,然后给出m条边,然后判断给出的有向图中是否存在负环. 解题思路:利用Bellman Ford算法,若进行第n次松弛时,还能 ...

  5. Lonsdor K518ISE programs 2005 Ford Focus key in two minutes

    A quick demonstration of Lonsdor K518ISE programming key for 2005 Ford Focus in two minutes. And for ...

  6. Ford VCM II Ford VCM2 Diagnostic Tool with Ford IDS v108 Installed On Laptop Ready to Use

    HOW to VCM2 Ford VCM II with Ford IDS v108 Work Well? VCM2 Ford VCM2 Ford diagnostic tool hot sale i ...

  7. How to install VCM 2 Ford IDS 109 software

    How to install Ford IDS 109: 1- Install the ids 86 before changing the date to 1 07 2015 (hold the d ...

  8. 求最短路径的三种算法: Ford, Dijkstra和Floyd

    Bellman-Ford算法 Bellman-Ford是一种容易理解的单源最短路径算法, Bellman-Ford算法需要两个数组进行辅助: dis[i]: 存储顶点i到源点已知最短路径 path[i ...

  9. Gym - 100851F Froggy Ford kruskal

    题目链接: http://acm.hust.edu.cn/vjudge/problem/307216 Froggy Ford Time Limit: 3000MS 题意 青蛙过河,河中有若干个石头,现 ...

  10. Bellman—Ford算法思想

    ---恢复内容开始--- Bellman—Ford算法能在更普遍的情况下(存在负权边)解决单源点最短路径问题.对于给定的带权(有向或无向)图G=(V,E),其源点为s,加权函数w是边集E的映射.对图G ...

随机推荐

  1. opencv 常用头文件介绍

    1.OpenCV包含的模块 cv – 核心函数库 cvaux – 辅助函数库 cxcore – 数据结构与线性代数库 highgui – GUI函数库 ml – 机器学习函数库 2.常用头文件: #i ...

  2. [LeetCode] Number of Subarrays with Bounded Maximum 有界限最大值的子数组数量

    We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...

  3. python +selenium +chrome/firefox 环境配置

    http://ftp.mozilla.org/pub/firefox/releases/ 各firefox版本下载地址 http://ftp.mozilla.org/pub/firefox/relea ...

  4. Ehcache 3.7文档—基础篇—XML Configuration

    你可以使用xml配置创建CacheManager,根据这个schema definition ( http://www.ehcache.org/documentation/3.7/xsds.html# ...

  5. PAT甲级1078 Hashing【hash】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805389634158592 题意: 给定哈希表的大小和n个数,使用 ...

  6. php删除文件夹

    function deldir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." & ...

  7. ubuntu下安装和配置pycharm和pyqt5

    参考网址:https://blog.csdn.net/qq_37541097/article/details/80021315 PyQt是Python语言的GUI编程解决方案之一.可以用来代替Pyth ...

  8. python 配置文件返回的两种方式,写法不一样而已

    配置文件如下: [MODE]mode:{ "register":"all"} 或者 mode = {"register":"all ...

  9. JS数组reduce()方法详解及高级技巧

    1.语法 arr.reduce(callback,[initialValue]) reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被删除或从未被赋值的元素,接受四个参数:初始值(或者上 ...

  10. keras,tensorflow,numpy,jupyter

    docker-tensorflow:https://segmentfault.com/a/1190000015053704 pip install scipy pip install keras do ...