DIJKSTRA 临接表
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int value[],to[],next[];
int head[],total;
int book[];
int dis[];
int n,m;
void adl(int a,int b,int c)
{
total++;
to[total]=b;
value[total]=c;
next[total]=head[a];
head[a]=total;
}
void dijkstra(int u)
{
memset(dis,,sizeof(dis));
memset(book,,sizeof(book));
dis[u]=;
for(int i=;i<=n;i++)
{
int start=-;
for(int j=;j<=n;j++)
if(book[j]== && (dis[start]>dis[j] || start==-))
start=j;
book[start]=;
for(int e=head[start];e;e=next[e])
dis[to[e]]=min(dis[to[e]],dis[start]+value[e]);
}
}
int main()
{
cin>>n>>m;
for(int i=;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
adl(a,b,c);
}
dijkstra();
for(int i=;i<=n;i++)
cout<<dis[i]<<" ";
}
DIJKSTRA 临接表的更多相关文章
- HDU 1874 畅通工程续(最短路/spfa Dijkstra 邻接矩阵+邻接表)
题目链接: 传送门 畅通工程续 Time Limit: 1000MS Memory Limit: 65536K Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路. ...
- 最短路 dijkstra+优先队列+邻接表
http://acm.hdu.edu.cn/showproblem.php?pid=2544 #include<iostream> #include<queue> #inclu ...
- hdu 1142 用优先队列实现Dijkstra
之前很认真地看了用优先队列来实现Dijkstra这块,借鉴了小白书上的代码模板后,便拿这道题来试试水了.这道题的大意就是问你从地点1到地点2有多少条满足条件的路径(假设该路径经过 1->...- ...
- HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)
Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...
- 狄斯奎诺(dijkstra 模板)
/*狄斯奎诺算法(dijkstra)<邻接表> */ #include<stdio.h> #include<string.h> #include<stdlib ...
- Dijkstra 最短路径算法 秒懂详解
想必大家一定会Floyd了吧,Floyd只要暴力的三个for就可以出来,代码好背,也好理解,但缺点就是时间复杂度高是O(n³). 于是今天就给大家带来一种时间复杂度是O(n²),的算法:Dijkstr ...
- HDU 1874 SPFA/Dijkstra/Floyd
这题作为模板题,解法好多... 最近周围的人都在搞图论阿,感觉我好辣鸡,只会跟风学习. 暂时只有SPFA和Dijkstra的 SPFA (邻接表版.也可以写成临接矩阵存图,但题目可能给出平行边的,所以 ...
- 洛谷 P3371 【模板】单源最短路径(弱化版) && dijkstra模板
嗯... 题目链接:https://www.luogu.org/problem/P3371 没什么好说的,这是一个最短路的模板,这里用的dijkstra做的... 注意: 1.dijkstra和邻接表 ...
- Heavy Transportation(最短路 + dp)
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- springboot2.0以后WebMvcConfigurationSupport代替WebMvcConfigurationAdapter
1:WebMvcConfigurationSupport代替WebMvcConfigurationAdapter https://blog.csdn.net/wilsonsong1024/articl ...
- 高性能平滑动画_requestAnimationFrame
高性能平滑动画_requestAnimationFrame 在下一次重绘之前,执行一个函数
- React 面向组件化编程 - 封装了webpack - npm run build 产生的包的 /static 引用路径问题
React 面向组件化编程 面向对象 ----> 面向模块 ----> 面向组件 套路: 注意: 组件名必须大写开头: 只能有一个根标签: <input />虚拟DOM 元素必 ...
- [LeetCode] Quad Tree Intersection 四叉树相交
A quadtree is a tree data in which each internal node has exactly four children: topLeft, topRight, ...
- linux学习:wget与lynx用法整理
指令:wget.lynx.axel wget url #下载数据写入文件,下载的文件名与url中的文件名保持一致,下载信息或进度写入stdoutwget url1 url2 url3 #下载多 ...
- 第二天(就业班) html的引入、html常用标签、实体标签、超链接标签、图片标签、表格、框架标签、表单[申明:来源于网络]
第二天(就业班) html的引入.html常用标签.实体标签.超链接标签.图片标签.表格.框架标签.表单[申明:来源于网络] 第二天(就业班) html的引入.html常用标签.实体标签.超链接标签. ...
- OO第四次博客作业
测试与正确性论证的效果差异及其优缺点 测试是利用测试代码,通过编写测试用例来验证代码是否能正常完成所要求的功能,自动测试相较于正确性论证来说更加的直观,直接测试代码的功能,而正确性论证是在JSF的基础 ...
- zhuan: WAN simulating tool - Netem : command tc qdisc
Last weekly meeting we talked about a WAN simulating tool in order to test WPG, I find a great tool ...
- maven jdk版本
http://maven.apache.org/docs/history.html Maven Releases History Date format is: YYYY-MM-DD Maven 3 ...
- onu-reg-unreg.vbs
Sub Main crt.Sleep 10000 Dim cnt For cnt = 0 To 1000000 crt.screen.Send "admin-status down" ...