题目链接:http://poj.org/problem?id=2387

题目大意:给你t条边(无向图),n个顶点,让你求点1到点n的最短距离。

解题思路:裸的dijsktra,注意判重边。

代码:

 #include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=1e3+; int dis[N],cost[N][N];
bool used[N];
int V,E; void dij(int s){
//初始化
for(int i=;i<=V;i++){
dis[i]=INF;
used[i]=false;
}
dis[s]=; while(true){
int k=-;
for(int i=;i<=V;i++){
if(!used[i]&&(k==-||dis[k]>dis[i]))
k=i;
}
if(k==-) break;
used[k]=true;
for(int i=;i<=V;i++){
dis[i]=min(dis[i],dis[k]+cost[k][i]);
}
}
} int main(){
memset(cost,0x3f,sizeof(cost));
scanf("%d%d",&E,&V);
for(int i=;i<=E;i++){
int a,b,len;
scanf("%d%d%d",&a,&b,&len);
//判重边
cost[a][b]=cost[b][a]=min(cost[a][b],len);
}
dij();
printf("%d\n",dis[V]);
return ;
}

POJ 2387 Til the Cows Come Home(dijkstra裸题)的更多相关文章

  1. POJ 2387 Til the Cows Come Home Dijkstra求最短路径

    Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...

  2. poj 2387 Til the Cows Come Home(dijkstra算法)

    题目链接:http://poj.org/problem?id=2387 题目大意:起点一定是1,终点给出,然后求出1到所给点的最短路径. 注意的是先输入边,在输入的顶点数,不要弄反哦~~~ #incl ...

  3. POJ 2387 Til the Cows Come Home (Dijkstra)

    传送门:http://poj.org/problem?id=2387 题目大意: 给定无向图,要求输出从点n到点1的最短路径. 注意有重边,要取最小的. 水题..对于无向图,从1到n和n到1是一样的. ...

  4. Poj 2387 Til the Cows Come Home(Dijkstra 最短路径)

    题目:从节点N到节点1的求最短路径. 分析:这道题陷阱比较多,首先是输入的数据,第一个是表示路径条数,第二个是表示节点数量,在 这里WA了四次.再有就是多重边,要取最小值.最后就是路径的长度的最大值不 ...

  5. POJ 2387 Til the Cows Come Home (图论,最短路径)

    POJ 2387 Til the Cows Come Home (图论,最短路径) Description Bessie is out in the field and wants to get ba ...

  6. POJ.2387 Til the Cows Come Home (SPFA)

    POJ.2387 Til the Cows Come Home (SPFA) 题意分析 首先给出T和N,T代表边的数量,N代表图中点的数量 图中边是双向边,并不清楚是否有重边,我按有重边写的. 直接跑 ...

  7. POJ 2387 Til the Cows Come Home

    题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K ...

  8. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  9. 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)

    Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33015   Accepted ...

  10. POJ 2387 Til the Cows Come Home (最短路 dijkstra)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...

随机推荐

  1. BZOJ1499:[NOI2005]瑰丽华尔兹——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1499 舞厅是一个N行M列的矩阵,矩阵中的某些方格上堆放了一些家具,其他的则是空地.钢琴可以在空地上滑 ...

  2. UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...

  3. SpringBoot-配置文件属性注入-3种方式

    配置文件: datasource.username = admin datasource.url = /hello/world 方式一: @Value 前提: <!-- JavaBean处理工具 ...

  4. redux的一些插件总结(redux-actions,reselect)

    redux本身还是过于简单,实际使用的时候需要配合许多插件. 下面是一些插件与vuex的功能对比 redux-actions <=> vuex的mutation的写法 reselect & ...

  5. angularJS前端分页插件

    首先在项目中引入 分页插件的 js 和 css: 在html页面引入 相关js 和 css: 在控制器中引入分页插件中定义的 module[可以打开pagination.js查看,可以看到 其实,在插 ...

  6. Spark获取某个手机号在某个基站下停留的时间和当前手机所在的位置的案例

    1.业务需求 在拥有手机号在每个基站处停留时间日志 和 基站信息的 算出某个手机号的(所在基站,停留时间),(当前所在经度,当前所在纬度) 其中手机连接基站产生的日志信息类似如下: 186888888 ...

  7. swift的UIbutton

    override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...

  8. Sightseeing(dijlstar) 计算最短路和次短路的条数

    Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10004   Accepted: 3523 Desc ...

  9. 解决在linux安装网易云音乐无法点击图标打开

    一下内容转载自:https://blog.csdn.net/Handoking/article/details/81026651 似乎linux下无法直接打开网易云音乐的原因是图标自带的启动脚本中没有 ...

  10. PowerDesigner16 把设计图导出成图片

    1. 用鼠标选择要导出的对象,必须先选择. 2. 选择Edit—>Export Image 导出为你需要的格式图片,见下图: