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. 【IDEA】IntelliJ IDEA Web调试控制台中文乱码问题

    RT,解决方法: Tomcat VM Options 配置参数 -Dfile.encoding=UTF-8,如图所示:

  2. [__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17deba00

    还真是一波未平一波又起,又出现了这个问题,详情如下: -[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized ...

  3. C++ protobuffer 前后端通信 简单应用

    后端发送多个protobuffer消息到前端,前端用socket监听,如何区分消息类型呢? //定义心跳包 DseHeartbeat _DseHeartbeat; DseHeartbeat _DseH ...

  4. python 处理json数据

    python 处理 json数据 以下是登录账号后获取的json数据,headers中注意加入cookie值 需要处理的数据如下: 全部代码如下 #!/usr/bin/env python # -*- ...

  5. 一个项目的SpringCloud微服务改造过程

    SSO是公司一个已经存在了若干年的项目,后端采用SpringMVC.MyBatis,数据库使用MySQL,前端展示使用Freemark.今年,我们对该项目进行了一次革命性的改进,改造成SpringCl ...

  6. 重启iis的命令是什么?三种简单的重启方式

    第一种.界面操作 打开“控制面板”->“管理工具”->“服务”.找到“IIS Admin Service” 右键点击“重新启动” 弹出 “停止其它服务” 窗口,点击“是”. 第二种.Net ...

  7. Paxos算法原理

    1.从ACID到CAP 我们知道传统集中式系统中实现ACID是很简单的,在分布式环境中,涉及到不同的节点,节点内的ACID可以控制,那么节点间的ACID如何控制呢?构建一个可用性和一致性的分布系统成为 ...

  8. 【openmp】for循环的break问题

    问题描述:在用openmp并行化处理for循环的时候,便无法在for循环中用break语句,那么我们如何实现这样的机制呢?在stackoverflow上看到一个不错的回答总结一下. volatile ...

  9. Javarscipt中数组或者字符串的随机排序方法

    在日常开发中,经常会遇到随机排序的需求,思路就是利用Math.random()方法,抽取随机数,让数组中的元素进行对调: 话不多说直接上代码,方法一:基本思路就是将a中随机抽取一个元素,放入b中,再从 ...

  10. socket基于TCP(粘包现象和处理)

    目录 6socket套接字 7基于TCP协议的socket简单的网络通信 AF_UNIX AF_INET(应用最广泛的一个) 报错类型 单一 链接+循环通信 远程命令 9.tcp 实例:远程执行命令 ...