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 ;
}

最新文章

  1. iOS - Apache Tomcat WebServer 服务器配置
  2. Linux服务器偶尔无法访问问题
  3. HDU 1881
  4. android92 aidl远程进程通信
  5. JavaScript中一些你不一定知道的问题(持续更新中。。。。)
  6. Goldbach&#39;s Conjecture(哥德巴赫猜想)
  7. 使用RadioGroup与RadioButton实现多选一
  8. 快学Scala-第二章 控制结构和函数
  9. 20175208《Java程序设计》第五周学习总结
  10. HttpClients+Jsoup抓取笔趣阁小说,并保存到本地TXT文件
  11. Java 8 新特性:5-Supplier、IntSupplier、BinaryOperator接口
  12. Studio启动的时候报错 Could not install Gradle distribution from
  13. 关于promise自己的理解
  14. 20155219 2016-2017-2 《Java程序设计》第7周学习总结
  15. 类库中使用WPF 资源文件
  16. Ubuntu14.04LTS下使用eclipse搭建Cocos2d-x的Android环境
  17. 安装Tomcat的Apr
  18. android checkbox样式
  19. ubuntu10.04 交叉编译 aria2 总结
  20. redhat6.5文件共享

热门文章

  1. Java连载10-数据类型取值范围&amp;转义字符
  2. input属性设置type=&quot;number&quot;之后, 仍可输入e, E, -, + 的解决办法
  3. idea 2018.3.4安装破解
  4. S2:log4j
  5. java订单生成工具类
  6. hadoop学习(七)----mapReduce原理以及操作过程
  7. Spring Boot + Security + JWT 实现Token验证+多Provider——登录系统
  8. Flink Metrics 源码解析
  9. (一)c#Winform自定义控件-基类控件
  10. Docker进阶-容器监控cAdvisor+InfluxDB+Granfana