BELLMEN-FORD普通
#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普通的更多相关文章
- ACM/ICPC 之 网络流入门-Ford Fulkerson与SAP算法(POJ1149-POJ1273)
第一题:按顾客访问猪圈的顺序依次构图(顾客为结点),汇点->第一个顾客->第二个顾客->...->汇点 //第一道网络流 //Ford-Fulkerson //Time:47M ...
- ACM/ICPC 之 最短路径-Bellman Ford范例(POJ1556-POJ2240)
两道Bellman Ford解最短路的范例,Bellman Ford只是一种最短路的方法,两道都可以用dijkstra, SPFA做. Bellman Ford解法是将每条边遍历一次,遍历一次所有边可 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- uva 558 - Wormholes(Bellman Ford判断负环)
题目链接:558 - Wormholes 题目大意:给出n和m,表示有n个点,然后给出m条边,然后判断给出的有向图中是否存在负环. 解题思路:利用Bellman Ford算法,若进行第n次松弛时,还能 ...
- 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 ...
- 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 ...
- 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 ...
- 求最短路径的三种算法: Ford, Dijkstra和Floyd
Bellman-Ford算法 Bellman-Ford是一种容易理解的单源最短路径算法, Bellman-Ford算法需要两个数组进行辅助: dis[i]: 存储顶点i到源点已知最短路径 path[i ...
- Gym - 100851F Froggy Ford kruskal
题目链接: http://acm.hust.edu.cn/vjudge/problem/307216 Froggy Ford Time Limit: 3000MS 题意 青蛙过河,河中有若干个石头,现 ...
- Bellman—Ford算法思想
---恢复内容开始--- Bellman—Ford算法能在更普遍的情况下(存在负权边)解决单源点最短路径问题.对于给定的带权(有向或无向)图G=(V,E),其源点为s,加权函数w是边集E的映射.对图G ...
随机推荐
- 为什么很多应用都安装在/usr/local目录下?
首先,Linux的官方文档FHS对该目录的说明:http://www.linuxbase.org/betaspecs/fhs/fhs/ch04s09.html The /usr/local hiera ...
- 根据文件大小自动判断单位B,KB,MB,GB
<php> /** * 文件大小格式化 * @param integer $size 初始文件大小,单位为byte * @return array 格式化后的文件大小和单位数组,单位为by ...
- jmeter实例介绍
JMeter基础之一 一个简单的性能测试 测试需求: 1)测试目标网站是fnng.cnblogs.com 和 tt-topia.rhcloud.com 2)测试目的是该网站在负载达到20 QPS 时 ...
- Solve Error: node postinstall sh: node: command not found
When install the yeoman using the following command: npm install -g yo You might have the following ...
- windows创建定时任务执行python脚本
一.创建定时任务 \ [程序或脚本]文本框中填的是Python编译器的名称,一般就是python.exe, [起始于]文本框中填的是Python编译器的目录,上图中假设你的Python编译器的完整路径 ...
- 使用ElasticSearch全文检索以及集群部署
ElasticSearch 即 ES 安装:版本---elasticsearch-2.4.6.tar.gz tar -zxvf elasticsearch-2.4.6.tar.gz 由于es不允许使 ...
- IIC稳定性.VBS
Sub Main Dim cnt Dim delay Dim time Dim atttime atttime = 20 delay = 3000 time = 50 crt.screen.Send ...
- MySQL 的安装
MySQL的全部安装步骤. 1::本案例要求熟悉MySQL官方安装包的使用,快速构建一台数据库服务器: 安装MySQL-server.MySQl-client软件包 修改数据库用户root的密码 确认 ...
- Eclipse中STM32工程建立步骤
前段时间一直在折腾linux系统上STM32的开发,网上一顿搜,费劲九牛二虎之力终于把环境搭好了(现在都有点忘了,后面再折腾环境搭建一定要写个教程,今天先不写了). 自从环境搭好之后,就基本抛弃MDK ...
- 微信小程序轮播图组件 swiper,swiper-item及轮播图片自适应
官网地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html index.wxml文件 indicator-d ...