http://acm.hdu.edu.cn/showproblem.php?pid=2544

 #include<iostream>
#include<queue>
#include<functional>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N = 1e3+;
const int INF = 1e7;
typedef pair<int, int> pll;
struct Node
{
int next;
int s;
Node(int nt, int d):next(nt), s(d){};
};
vector<Node> G[N];
int dis[N];
void dijkstra()
{
priority_queue<pll, vector<pll>, greater<pll> >q;
q.push(pll (,));// 距离 位置
while(!q.empty())
{
pll temp = q.top(); q.pop();
int x = temp.second, ss = temp.first;
if(dis[x]!= ss)
continue;
for(int i = ; i < G[x].size(); i++)
{
int y = G[x][i].next, d = G[x][i].s;
if( dis[y] > dis[x] + d)
{
dis[y]= dis[x]+d;
q.push(pll (dis[y],y));
}
}
}
}
void init(int n)
{
for(int i = ; i <= n; i++)
{
dis[i] = INF;
G[i].clear();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, m;
while(cin >> n >> m, n+m)
{
init(n);
int x, y, d;
for(int i = ; i <= m; i++)
{
cin >> x >> y >> d;
G[x].push_back(Node(y,d));
G[y].push_back(Node(x,d));
}
dis[] = ;
dijkstra();
cout << dis[n] << endl;
}
return ;
}

最短路 dijkstra+优先队列+邻接表的更多相关文章

  1. HDU 1874 畅通工程续(最短路/spfa Dijkstra 邻接矩阵+邻接表)

    题目链接: 传送门 畅通工程续 Time Limit: 1000MS     Memory Limit: 65536K Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路. ...

  2. Codeforces Gym101502 I.Move Between Numbers-最短路(Dijkstra优先队列版和数组版)

    I. Move Between Numbers   time limit per test 2.0 s memory limit per test 256 MB input standard inpu ...

  3. HDU 1874-畅通project续(最短路Dijkstra+优先队列)

    畅通project续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 最短路--dijkstra+优先队列优化模板

    不写普通模板了,还是需要优先队列优化的昂 #include<stdio.h> //基本需要的头文件 #include<string.h> #include<queue&g ...

  5. POJ - 2387 Til the Cows Come Home (最短路Dijkstra+优先队列)

    Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before ...

  6. 最短路 dijkstra 优先队列

    1.裸题 hdu2544 http://acm.hdu.edu.cn/showproblem.php?pid=2544 Way1: 好像不对 #include <cstdio> #incl ...

  7. HDOJ 2544 最短路(最短路径 dijkstra算法,SPFA邻接表实现,floyd算法)

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...

  9. USACO 2008 January Silver Telephone Lines /// 二分最短路 邻接表dijkstra oj22924

    题目大意: 一共有N (1 ≤ N ≤ 1,000)个电线杆,有P P (1 ≤ P ≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆 ...

随机推荐

  1. 并发编程之Java内存模型

    在介绍Java内存模型之前,先来了解一下为什么要有内存模型,以及内存模型是什么.然后我们基于对内存模型的了解,学习Java内存模型以及并发编程的三大特性. 为什么要有内存模型 在计算机中,所有的运算操 ...

  2. Eclipse "Adb failed to restart !"

    今天遇到这个问题,如图所示: 上网找了下,原来是电脑上的各种手机助手抢占了手机链接.http://blog.csdn.net/zhufuing/article/details/19398125 说得很 ...

  3. cesium学习——cesium中的坐标

    一.坐标展现形式 在cesium中,对于坐标数值单位有三种:角度.弧度和坐标值 1.角度 角度就是我们所熟悉的经纬度,对于地球的坐标建立如下: 图中以本初子午线作为x和z的面,建立了一个空间坐标系.可 ...

  4. Pyenv虚拟环境的创建(虚拟机)

    创建pyenv虚拟环境 sudo yum install openssl* 安装其所需要的库文件 git clone https://github.com/yyuu/pyenv.git ~/.pyen ...

  5. Linux及Windows下ActiveMQ下载与安装教程

    原文连接:(http://www.studyshare.cn/blog-front//blog/details/1170/0 )一.下载 Windows: 1.官网下载地址:这里 2.百度网盘下载:这 ...

  6. 前端本地proxy跨域代理配置

    等了好久的接口,总算拿到了,结果却发现用本地localhost:9712去请求接口的时候,出现了跨域错误,而这个时候我们就需要进行下跨域配置了. 首先,找到项目中名为webpack.config.js ...

  7. 对vue中nextTick()的理解及使用场景说明

    异步更新队列: 首先我们要对vue的数据更新有一定理解: vue是依靠数据驱动视图更新的,该更新的过程是异步的. 即:当侦听到你的数据发生变化时, Vue将开启一个队列(该队列被Vue官方称为异步更新 ...

  8. 【Kubernetes 系列四】Kubernetes 实战:管理 Hello World 集群

    目录 1. 创建集群 1.1. 安装 kubectl 1.1.1. 安装 kubectl 到 Linux 1.1.2. 安装 kubectl 到 macOS 1.1.3. 安装 kubectl 到 W ...

  9. 洛谷 P4401 [IOI2007]Miners 矿工配餐

    题意简述 有两个矿洞,已知食物的种类(≤3)和顺序,将他们送往任一矿洞, 若一个矿洞3次食物相同,贡献1:若有2种不同食物,贡献2:若有3种不同食物,贡献3 求最大贡献 题解思路 food[i] 为当 ...

  10. R 实用命令 1

    Quit and restart a clean R session from within R? If you're in RStudio: command/ctrl + shift + F10 . ...