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 ...
随机推荐
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)
A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...
- hadoop2-hive
hadoop2-hive 1.What,Why,How? 1.Hive是数据仓库,在MySQL或其他关系型数据库中存放元数据信息,而把真正的Data存放在HDFS上面. 2.主要使用Hive来对历史数 ...
- css样式兼容各个浏览器时的部分总结
[本文基本是在网络转发过来的,网站就忘记了,这文本都是保存在自己电脑本地的,还有些自己添加了些内容,这内容还会有不断的完善和更行的] 什么是浏览器兼容:当我们使用不同的浏览器(Firefox IE7 ...
- Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Unable to compile class for JSP] with root cause java.lang.IllegalArgumentException: Page directive: inval
严重: Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Una ...
- appium api笔记
打印上下文driver.contexts打印当前上下文driver.contextdriver.current_context切换上下文driver.switch_to.context('WEBVIE ...
- hive时间日期函数及典型场景应用
1.hive取得当前日期时间: 1.1) 取得当前日期: select current_date(); 1.2) 取得当前日期时间: select current_timestamp(); 1.3) ...
- java集成微软的ad域,实现单点登录
1.ad域介绍: windos server 2008R2服务器下的ad域,见下图(我是在虚拟机安装到windos server) 2.连接ad域代码:(里面代码自行修改) public Result ...
- [git] git怎样fork一个repo
描述 我定制了一下strongswan的工程.然后想把我自己的定制变成一个repo push到远端git.tong.com与大家分享. 这个时候,应该怎么做? 如果你用过github的话.那么你可以理 ...
- IP,IP地址,mac地址
IP地址与IP是两个不同的概念.单独讲IP,是指IP协议 IP地址分为三类:单播地址(目的为单个主机):多播地址(目的端为同一组的所有主机):广播地址(目的端为网络上所有给定的主机) ip地址由网络和 ...
- 2019春第十周作业Compile Summarize
这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 在这里 我在这个课程的目标是 能够对C语言的编写更加得心应手 这个作业在那个具体方面帮助我实现目标 结构体更进一步 参考文献与网址 C语言 ...