poj2387 Til the Cows Come Home(dijkstra)
来源:互联网 发布:java编程视频教程 编辑:程序博客网 时间:2024/06/05 17:51
题目链接:http://poj.org/problem?id=2387
解析:大意就是给你一个图,找从一号结点到n号结点的最短路,这个最短路一定会存在,让你输出这个结果
解析:自己脑残写错了代码,看了讨论,发现这题确实坑。。。要注意一下重边,额。。。数据范围也有错,不过正常邻接表,最大值设大一点,不写错代码,应该就能1A的,毕竟裸题
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>using namespace std;const int maxn = 1e5+100;const int inf = 0x7fffffff;vector<pair<int,int > >G[maxn];int d[maxn];void dj(int s,int n){ fill(d,d+n+1,inf); d[s] = 0; priority_queue<pair<int,int> >q; q.push(make_pair(-d[s],s)); while(!q.empty()) { int u = q.top().second; q.pop(); for(int i=0;i<(int)G[u].size();i++) { pair<int,int> v = G[u][i]; if(d[v.first]>d[u]+v.second) { d[v.first] = d[u]+v.second; q.push(make_pair(-d[v.first],v.first)); } } } printf("%d\n",d[n]);}int main(void){ int t,n; scanf("%d %d",&t,&n); for(int i=0;i<t;i++) { int x,y,z; scanf("%d %d %d",&x,&y,&z); G[x].push_back(make_pair(y,z)); G[y].push_back(make_pair(x,z)); } dj(1,n); return 0;}
阅读全文
0 0
- POJ2387 Til the Cows Come Home【Dijkstra】
- POJ2387----Til the Cows Come Home(dijkstra)
- POJ2387 Til the Cows Come Home(dijkstra)
- poj2387 Til the Cows Come Home (dijkstra)
- POJ2387 - Til the Cows Come Home(Dijkstra)
- poj2387~Til the Cows Come Home(最短路dijkstra)
- poj2387 Til the Cows Come Home(dijkstra)
- POJ2387--Til the Cows Come Home(dijkstra)
- POJ2387 Til the Cows Come Home——Heap+dijkstra
- POJ2387--Til the Cows Come Home--Dijkstra算法裸题
- poj2387-Til the Cows Come Home dijkstra入门水题
- POJ2387 Til the Cows Come Home -DIJKSTRA 练习
- poj2387 Til the Cows Come Home—Dijkstra模板
- POJ2387 Til the Cows Come Home(dijkstra求图论最短路)
- POJ2387 Til the Cows Come Home(dijkstra + heap 或 SPFA)
- POJ2387--Til the Cows Come Home(dijkstra算法)
- Til the Cows Come Home (Dijkstra)
- poj2387- Til the Cows Come Home
- java中经常用到的自动装箱和自动拆箱
- 1.5Java函数(方法)
- 第十篇:ndk项目实战之Androidstudio开发经验总结
- C语言:字符串子串判断
- java基础(五)之JAVA编码规范
- poj2387 Til the Cows Come Home(dijkstra)
- 数据库设计中应注意的问题
- 第十一篇:C代码调用Java代码之项目实战
- HDU 4002 数论
- springboot学习笔记五
- BDKR_hashz字符串(自己的理解)
- hdu 2680 Choose the best route【dijstra+反向建图】
- POJ
- 58面试整理